I’m trying to do a simple regex that searches for a few characters and such within sections, including looking for the . literal. However, the Pattern compiler is saying it isn’t valid.
The following is an excerpt from the full regex that throws the format exception. The escape looks right, it just sees the . as something that shouldn’t be escaped.
([a-zA-Z0-9_-\.\s]{1,})
^
I have also tried "([a-zA-Z0-9_-\\\\.\\s]{1,})" (same as above but with two \ to escape the .) with no luck.
All of the resources I could find on the internet for escaping the dot character have stated this should work.
What am I missing?
Problem is not in
.but in-before it. Try"([a-zA-Z0-9_\\-.\\s]{1,})"-is metacharacter in character class[...]. It specifies range of characters like[a-z]can match character betweenaandz(inclusive) in Unicode Table. If you use it in place where there will be no possibility to treat is as range operator like at start or end of character class[-...][...-]it will be treated as normal character so in that cases you will not have to escape it. Otherwise you will need to use\before it to change it into simple literal.