[英]Regex matching into multiple groups per line?
I'm trying to come up with a regex to be able to parse the following type of strings into groups. 我正试图提出一个正则表达式,以便能够将以下类型的字符串解析为组。
<link rel="alternate" type="application/rss+xml" title="[!PageTitle!]" href="[!SiteRoot!]/feed.xml" />
My regular expression is: 我的正则表达式是:
\[\!(.+)\!\]
The problem with this expression is that it seems to pull it all into 1 group: 此表达式的问题在于,似乎将它们全部归为一组:
Found 1 match: 找到1个匹配项:
"[!PageTitle!]" href="[!SiteRoot!]" has 1 group: “ [!PageTitle!]” href =“ [!SiteRoot!]”有1个群组:
1. "PageTitle!]" href="[!SiteRoot"
I want dont want the regex to continue...am I missing a boundary? 我不想让正则表达式继续...我错过边界了吗? Ideally I want it to find 2 groups ,
理想情况下,我希望它找到2个群组 ,
[!PageTitle!] [!页面标题!]
and 和
[!SiteRoot!] [!SiteRoot!]
try: 尝试:
\[\!(.+?)\!\]
the +
quantifier is greedy, so will match as far as possible in the line, capturing the first [ followed by the last ] in the line. +
量词是贪婪的,因此将在行中尽可能匹配,以捕获行中的第一个[后一个最后一个]。 +?
is the non-greedy equivalent. 是非贪婪的等价物。
As an aside, I'm using Rad Software Regular Expression Designer . 顺便说一句,我正在使用Rad Software正则表达式设计器 。 I like it.
我喜欢。
似乎这样可以正常工作:)
\[!(\w+)!\]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.