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

match everything inside of * with no whitespaces

I want a regex to have the following behaviour:

*test and test* -> match ok
* test and test* -> match NOT ok
*test and test * -> match NOT ok
* test and test * -> match NOT ok

I was using this regex to get it working: \*[^\s](.*?)[^\s]\*
But the problem is, in group #1, it cuts the first and last letter, so instead of having a match test and test, I end up with est and tes, I need to keep both first and last letter while also having whitespace in between the words

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

>Solution :

You just don’t have the first and last letter inside your capture group (denoted by the parenthesis).

Try this: \*([^\s].*?[^\s])\*

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