Reputation: 1325
The conditions of the regex that I'm trying to figure out are this:
It starts with either digits/asterisks or a '+' sign and ends with digits/asterisks.
It always requires always a minimum of 2 digits.
Example valid strings:
240*******
+12*
216438827*
*164*8827*
********21
I have been a few hours trying to solve it, but I'm stuck at this regex expression /^\+?[\d*]{2,}$/
, I cannot figure out how to set the 2 min. digits requirement, so I'll really appreciate some help, thanks!
A related screenshot:
Upvotes: 1
Views: 645
Reputation: 626747
You may use
^\+?(?:\**\d){2,}\**$
See the regex demo
Details
^
- start of string\+?
- an optional +
(?:\**\d){2,}
- two or more occurrences of:
\**
- 0+ *
chars\d
- a digit\**
- a *
symbol$
- end of string.Upvotes: 1