繁体   English   中英

匹配以下正则表达式:#*:*#

[英]Match the following regex: #*:*#

我想找到一个字符串是否包含一个以哈希(#)开头和结尾并包含冒号(:)的正则表达式。 所有这些都应该在同一条线上匹配

示例:你好#some:test#和george MATCH

示例:你好#:#world NO MATCH

示例:你好#test:#world NO MATCH

示例: hello#:test#world NO MATCH

例:

你好[换行]

#some:test#world NO MATCH

谢谢,Yannis

这应该做:

@"\#.+:.+\#"

分解:

\#   - Match a # character
.+   - Followed by one or more characters
:    - Followed by a : character
.+   - Followed by one or more characters
\#   - Followed by a # character

请注意. 将匹配任何字符,可能不是最有效的正则表达式。


非贪婪版本(更高效):

@"\#[^:]+:[^#]+\#"

\#    - Match a # character
[^:]+ - Followed by one or more characters that are not :
:     - Followed by a : character
[^#]+ - Followed by one or more characters that are not #
\#    - Followed by a # character

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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