Expression expression to start with 2 * not allowed

I would like to know a regex in order to prevent a string like

**Test 

but a string like

 *test, test,123, 

allowed. So basically starting with 2 Asterix (*) is not allowed, everything is allowed.

I tried the following regex expression

[^(\*{2})].* [^(\*\*)].* [^(\*\*)$].* ^(?!\*\*.*)

+5
source share
2 answers

Use negative viewing at the beginning to avoid two stars coinciding.

 /^(?!\*\*).*/ // or /^(?!\*{2}).*/ 
+4
source

Using Regex 101 I managed to find * after * with this

 (\*[^*]+.*) 

and then I ran or for other lines like

 ^((\*[^*]+.*)|([^*]+.*))$ 
0
source

Source: https://habr.com/ru/post/1275803/


All Articles