Re: Regex repeating capture
- From: "Mythran" <kip_potter@xxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 09:23:56 -0800
<jaylucier@xxxxxxxxx> wrote in message news:1170174574.488763.29890@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Howdy,
I'm trying to break an input string into multpile pieces using a
series of delimiters that start with an asterisk. Following the
asterisk is a mulitple character identifier immediately followed by a
data string of variable length. The input string may contain more than
one identifier anywhere in the string.
Here is an example:
*CZ1 2.3 4-56 *fuuuS24364 08 23 72
I'd like to break this into
CZ
1 2.3 4-56
fuuu
S24364 08 23 72
I have tried the pattern (?:\*(CZ|fuuu)(.*)), which produces the
following ouput:
CZ
1 2.3 4-56 *fuuuS24364 08 23 72
How can I force it to repeat the capturing?
Thanks,
Jay
So, to split based on an * using a regular expression:
string pattern = @"\*(?<Text>[^\*]+)";
string input = "*CZ1 2.3 4-56 *fuuuS24364 08 23 72";
Match match = Regex.Match(input, pattern);
while (match.Success) {
Console.WriteLine(match.Groups["Text"].Value);
match = match.NextMatch();
}
HTH,
Mythran
.
- Follow-Ups:
- Re: Regex repeating capture
- From: Mythran
- Re: Regex repeating capture
- References:
- Regex repeating capture
- From: jaylucier
- Regex repeating capture
- Prev by Date: Re: Programatically uninstall/install a service.
- Next by Date: Re: Best way to fire event
- Previous by thread: Re: Regex repeating capture
- Next by thread: Re: Regex repeating capture
- Index(es):
Relevant Pages
|
Loading