簡體   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