I have such a regex:
'(?:\$|сум)(\040)?(\d+)|(\d+)(\040)?(?:\$|сум)'
It matches the following strings:
$23
23$
1000сум
сум1000
сум 1000
1000 сум
I want to limit the number of digits in this regex to 8.
Tried this:
'(?:\$|сум)(\040)?(\d{, 8})|(\d{, 8})(\040)?(?:\$|сум)'
It stopped matching anything.
What am I doing wrong?
By combining the interval quantifier with the surrounding start- and end-of-string anchors, the regex will fail to match if the subject text's length falls outside the desired range.
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. Something like ^[2-9][1-6]$ matches 21 or even 96!
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .
\d{, 8}
Means nothing .Engine will match it literally and so your regex failed.
Use
\d{0,8}
No spaces inside {}
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