gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:16:08 24 4
gpt4 key购买 nike

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

最佳答案

您可以使用正则表达式:

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com