I need a regex for 5 digits in increasing order, like 12345
, 24579
, 34680
, and so on.
0
comes after 9
.
match(/(\d{5})/g);
\\. matches the literal character . . the first backslash is interpreted as an escape character by the Emacs string reader, which combined with the second backslash, inserts a literal backslash character into the string being read. the regular expression engine receives the string \.
\d is a digit (a character in the range [0-9] ), and + means one or more times. Thus, \d+ means match one or more digits. For example, the string "42" is matched by the pattern \d+ .
\d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ). \s (space) matches any single whitespace (same as [ \t\n\r\f] , blank, tab, newline, carriage-return and form-feed).
You can try (as seen on rubular.com)
^(?=\d{5}$)1?2?3?4?5?6?7?8?9?0?$
^
and $
are the beginning and end of string anchors respectively\d{5}
is the digit character class \d
repeated exactly {5}
times(?=...)
is a positive lookahead?
on each digit makes each optional\d{5}
till the end of the stringLet's say that we need to match strings that consists of:
[aeiou]
Then the pattern is (as seen on rubular.com):
^(?=[aeiou]{1,3}$)a?e?i?o?u?$
Again, the way it works is that:
(?=[aeiou]{1,3}$)
If each digit can repeat, e.g. 11223
is a match, then:
?
(zero-or-one) on each digit,*
(zero-or-more repetition) That is, the pattern is (as seen on rubular.com):
^(?=\d{5}$)1*2*3*4*5*6*7*8*9*0*$
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