我需要一个正则表达式,其中允许以任何顺序使用空格、括号和连字符的任何数字。但是有必须最后是“+”(加号)。
最佳答案
您可以使用正则表达式:
^[\d() -]+\+$
解释:
^ : Start anchor
[ : Start of char class.
\d : Any digit
( : A literal (. No need to escape it as it is non-special inside char class.
) : A literal )
: A space
- : A hyphen. To list a literal hyphen in char class place it at the beginning
or at the end without escaping it or escape it and place it anywhere.
] : End of char class
+ : One or more of the char listed in the char class.
\+ : A literal +. Since a + is metacharacter we need to escape it.
$ : End anchor
关于regex - 正则表达式 : numbers spaces parentheses +,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5409135/