Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I replace repeated complex strings in javascript?

For example, the input would be:

@[facts.::ip](facts.::ip) = "127.0.0.1" AND @[facts.::os](facts.::os) = "ubuntu"

I would like to transform that into:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

facts.::ip = "127.0.0.1" AND facts.::os = "ubuntu"

Thanks in advance!

I have tried to check for regex, but I do not have experience with it

>Solution :

Below regular expression method achieves required string transformation.

let from = '@[facts.::ip](facts.::ip) = "127.0.0.1" AND @[facts.::os](facts.::os) = "ubuntu"';
let to = from.replace(/(@\[([^\]\)]+)\]\(\2\))/g, "$2");
console.log(to);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading