regex - 正则表达式 : numbers spaces parentheses +

标签 regex

我需要一个正则表达式,其中允许以任何顺序使用空格、括号和连字符的任何数字。但是有必须最后是“+”(加号)。

最佳答案

您可以使用正则表达式:

^[\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/

相关文章:

php - 正则表达式获取括号内的文本

javascript - 正则表达式只捕获第一行

c# - 字符串格式检查给出意外结果(正则表达式)

java - 为什么没有像 Java 中的 for\\t、\\n、\\r 和\\f 那样针对退格字符 ("\b") 的特殊正则表达式构造?

regex - Grep不显示结果,在线正则表达式测试器可以显示结果

java正则表达式字符串被 "not\"分割

Python 通读文件直到匹配,读取直到下一个模式

python - 单词不以数字开头

regex - 如何在 VIM 中使用正则表达式检测代码行

javascript - 正则表达式匹配除 ".js"之外的所有字符