简体   繁体   English

PCRE 正则表达式必须在模式中间包含一个符号

[英]PCRE Regex MUST contain a symbol in middle of pattern

Trying to match a pattern where a symbol MUST occur in the middle of the pattern.试图匹配一个符号必须出现在模式中间的模式。

https://regex101.com/r/Z8CIFD/1 https://regex101.com/r/Z8CIFD/1

("fi[\w\W]{15,55}me")

The regex should look for and capture "file.name" but the pattern MUST contain " or + in the middle of the match. Example: should match the last two, but not the first.正则表达式应该寻找并捕获“file.name”,但模式必须在匹配的中间包含“或+。例如:应该匹配最后两个,而不是第一个。

"file.name"
"fi"+"le.na"+"me"
"f"+"il"+"e.n"+"a"+"me"

Worked on this a while and can't get it.在这方面工作了一段时间,无法得到它。 Any help is appreciated.任何帮助表示赞赏。

Use a positive lookahead that matches .+[+"]. , which matches + or " somewhere in the middle of the text.使用匹配.+[+"].的正向前瞻,匹配文本中间某处的+"

(?=.+[+"].)"f["+]*i["+]*l["+]*e["+]*\.["+]*n["+]*a["+]*m["+]?e"

The main pattern after the lookahead matches "file.name" with any number of " and + between each character.前瞻之后的主要模式匹配"file.name" ,每个字符之间有任意数量的"+ "

DEMO演示

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

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