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

Regex with double asterisk javascript

I need two regular expressions, one to get ** at the beginning of a string, and one at the end.

For example:

This is a **text** test

With an expression obtain the ** of the beginning and with another those of the end. There may be many more repetitions.

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

I have tried the following:

(\*\*)
^(\*\*)
/\*\*/
^/\*\*/

Thanks a lot

This **would** be a good **text** to do some **testing**

It should mark all the words that contain ** at the beginning.
And with the other you should mark all the ones that end with **

>Solution :

To match ** just before a word use:

\B\*\*\b
  • \B – is inverse of \b. It matches where \b doesn’t
  • \b – asserts position at a word boundary i.e. (^\w|\w$|\W\w|\w\W)

RegEx Demo 1

And to match ** just after a word use:

\b\*\*\B

RegEx Demo 2

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