简体   繁体   中英

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 string? ie '(' 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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM