Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex expression for start with 2 * is not allowed

Tags:

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})].* [^(\*\*)].* [^(\*\*)$].* ^(?!\*\*.*)

like image 895
Sarfraz Shaikh Avatar asked Mar 09 '18 07:03

Sarfraz Shaikh


People also ask

What does ?= * Mean in regex?

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).

What does regex 0 * 1 * 0 * 1 * Mean?

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.

What is the difference between * and *??

*? 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: . *? , .

What does \f mean in regex?

Definition and Usage The \f metacharacter matches form feed characters.


1 Answers

Use negative lookahead at the start to avoid matching 2 stars.

/^(?!\*\*).*/

// or

/^(?!\*{2}).*/
like image 108
Pranav C Balan Avatar answered Nov 15 '22 05:11

Pranav C Balan