Regex match multiple per line

  • Thread starter Thread starter DKode
  • Start date Start date
D

DKode

I have the following regex that I am using:

Match match = Regex.Match(global, "%(?<column>.+?)%");

my input string (global) is this:
"something\%username%\somethingelse\%match2%\some\%match3%

I want it to match "username","match2" and "match3"

but it only matches %username%, it doesnt continue on and get the other
matches

match.Groups.Count is equal to 2, which i assume, 0 is the whole string
and 1 is "%username%

How do I get it so it matches all of the strings between %%

thanks

dkode
 
I have the following regex that I am using:

Match match = Regex.Match(global, "%(?<column>.+?)%");

my input string (global) is this:
"something\%username%\somethingelse\%match2%\some\%match3%

I want it to match "username","match2" and "match3"

but it only matches %username%, it doesnt continue on and get
the other matches

match.Groups.Count is equal to 2, which i assume, 0 is the whole
string and 1 is "%username%

How do I get it so it matches all of the strings between %%

dkode,

Use a MatchCollection object and the Regex.Matches method:


MatchCollection matches = Regex.Matches(global, "%(?<column>.+?)%");

foreach (Match m in matches)
Console.WriteLine(m.Groups["column"].ToString());
 
Back
Top