How to modify regex to allow brackets
I have the following regex:
[0-9.-]+
What do I need to add to allow brackets at any point in the input st开发者_开发知识库ring? i.e '(' or ')'
Here is the regex that support brackets
[0-9.\-\[\]]+
here is the regex that support parenthesis
[0-9.\-\)\(]+
and both
[0-9.\-\)\(\[\]]+
Well, you can just add them to the regex with something like [0-9.\)\(-]+
but, since you're complicating the expression, you'll probably need to check for balance as well.
In other words, that regex is quite happy to accept 74.7((((((((((((2)
which is not really well-formed. But, since you're original accepted ...........2.2.2.22222...
, that may not be a great concern :-)
精彩评论