Match regular expressions across multiple groups per line?

I am trying to create a regex to be able to parse the following types of strings in groups.

<link rel="alternate" type="application/rss+xml" title="[!PageTitle!]" href="[!SiteRoot!]/feed.xml" /> 

My regex is:

 \[\!(.+)\!\] 

The problem with this expression is that it seems to be pulling it all out into one group:

Found 1 matches:

  • "[! PageTitle!]" Href = "[! SiteRoot!]" Has 1 group:

      1. "PageTitle!]" href="[!SiteRoot" 

I want regex not to continue ... am I missing the border? Ideally, I want to find 2 groups ,

[! PageTitle!]

and

[! Site root]

+1
c # regex
Mar 08 2018-10-10T00:
source share
2 answers

to try:

 \[\!(.+?)\!\] 

The + coefficient is greedy, so it will match, as far as possible, in the line, capturing the first [after the last] in the line. +? is the non-living equivalent.

As an aside, I use the Rad Software Regular Expression Designer . I like it.

+1
Mar 08 '10 at 1:10
source share

It seems to work fine :)

 \[!(\w+)!\] 
0
Mar 08 '10 at 1:13
source share



All Articles