Could someone tell me what the regular expression would be to match:
number with n
digits where n
would be provided or (
or )
To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.
match(/(\d{5})/g);
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.
Simple:
\(|\)|\d{n}
replace n
with the number of digits you need. If you need to match a complete string, then put parentheses around the expression and prepend ^
and append $
.
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