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
>Solution :
You just don’t have the first and last letter inside your capture group (denoted by the parenthesis).
Try this: \*([^\s].*?[^\s])\*