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

Markdown: regex to match **bold** in this string: `- **(450.00/450.00000000) * 100**`

This works

var str = '- **(450.00/450.00000000) x 100**'
str = str.replace(/[\*]{2}([^\*]+)[\*]{2}/g, '<B>$1</B>');
console.log(str);

but this does not work

var str = '- **(450.00/450.00000000) * 100**'
str = str.replace(/[\*]{2}([^\*]+)[\*]{2}/g, '<B>$1</B>');
console.log(str);

because /[\*]{2}([^\*]+)[\*]{2}/g stops at the first asterisk (* 100) and then determines it is not a match because there is only one asterisk, not two.

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

How can I get the regex to ignore the * 100 and match ** at the end of the line?

>Solution :

IF the possible alternatives to be matched are just the 2 options in your question, this: /[\*]{2}(.*)[\*]{2}/ should do the work.

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