[英]How do I execlude only numbers in this regular expression?
I'm trying to match words that look like this我正在尝试匹配看起来像这样的单词
:test:
:soda_stream:
:test3:
and so on.等等。 What I have now is \:\S+\:
and it works for everything except I also have parts in the text that have only numbers, like :23:
.我现在拥有的是\:\S+\:
它适用于一切,除了我在文本中也有部分只有数字,比如:23:
。 These I want to exclude, but are unsuccessful in doing that.这些我想排除,但没有成功。 I took a look at this StackOverflow page, but it does not work.我看了一下这个StackOverflow 页面,但它不起作用。
Do anyone know how to do it?有谁知道该怎么做? It probably is just some addition that exclude if there is only numbers inside the :
's.如果:
中只有数字,它可能只是一些排除。
Taking into account current examples, you may use考虑到当前示例,您可以使用
:(?!\d+:)[^\s:]+:
See the regex demo查看正则表达式演示
Details细节
:
- a colon :
- 一个冒号(?:\d+:)
- a negative lookahead that fails the match if there are one or more digits and then :
immediately to the right of the current location (?:\d+:)
- 如果有一个或多个数字,则匹配失败的负前瞻,然后:
紧挨当前位置的右侧[^\s:]+
- 1 or more characters other than whitespace and a colon [^\s:]+
- 除空格和冒号之外的 1 个或多个字符:
- a colon :
- 一个冒号As an alternative, you could match at least a single char that is not a digit or a whitespace char in between the colons:作为替代方案,您可以在冒号之间匹配至少一个不是数字或空格字符的单个字符:
:[^:\s]*[^:\s\d][^:\s]*:
:
Match literally :
从字面上匹配[^:\s]*
Match 0+ times any char except: or a whitespace char [^:\s]*
匹配任何字符 0+ 次,除了: 或空白字符[^:\s\d]
Match any char except: or a whitespace char or a digit [^:\s\d]
匹配除: 或空白字符或数字以外的任何字符[^:\s]*
Match 0+ times any char except: or a whitespace char [^:\s]*
匹配任何字符 0+ 次,除了: 或空白字符:
Match literally :
从字面上匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.