I would like to know the regex for not allowing string like
**Test
but string like
*test, test,123,
is allowed. So basically start with 2 Asterix(*) is not allowed rest everything is allowed.
I have tried following regex expression
[^(\*{2})].*
[^(\*\*)].*
[^(\*\*)$].*
^(?!\*\*.*)
is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1. 1* means any number of ones.
*? is non-greedy. * will match nothing, but then will try to match extra characters until it matches 1 , eventually matching 101 . All quantifiers have a non-greedy mode: . *? , .
Definition and Usage The \f metacharacter matches form feed characters.
Use negative lookahead at the start to avoid matching 2 stars.
/^(?!\*\*).*/
// or
/^(?!\*{2}).*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With