0

I just can't get my head around regex and this is driving me crazy.

I have the following string;

'This is a random string of text with a link to google.com/test and another link to facebook.com`

What I want to do, is turn google.com/test into https://google.com/test but leave the facebook.com link as plain text.

So basically, any instance of google.com (Including with prefixes) would turn into a link, but any other URL would remain as plain text.

Can someone give me a nudge in the right direction please?

0

1 Answer 1

2

Simple replace() will do:

var str = 'This is a random string of text with a link to google.com/test and another link to facebook.com';
str = str.replace('google.com/test', 'https://google.com/test');
console.log(str);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.