This is in Java: [1-57-9]
I came across this regular expression today, and I am trying to find out what it means exactly. Can anyone help me here?
It's allowing the digits 1-5 and 7-9. So it's equivalent to [12345789].
See the docs for Pattern for the details of regular expressions in Java, in particular the examples under "Character classes":
[abc]-a,b, orc(simple class)[^abc]- Any character excepta,b, orc(negation)[a-zA-Z]-athroughzorAthroughZ, inclusive (range)[a-d[m-p]]-athroughd, ormthroughp:[a-dm-p](union)[a-z&&[def]]-d,e, orf(intersection)[a-z&&[^bc]]-athroughz, except forbandc:[ad-z](subtraction)[a-z&&[^m-p]]-athroughz, and notmthroughp:[a-lq-z](subtraction)
See also the regular-expressions.info web site, and its section on character classes.
Read [1-57-9] as "1 to 5 or 7 to 9"
It matches a digit in 1, 2, 3, 4, 5, 7, 8, 9.
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