Re: Regex repeating capture
- From: jaylucier@xxxxxxxxx
- Date: 30 Jan 2007 09:08:47 -0800
Sorry, this was a simple example. In all, there are 50+ identifiers
and * is allowed in that data as long it isn't immediately followed by
an identifier, otherwise it is considered another identifier.
On Jan 30, 11:58 am, "Peter Bradley" <pbrad...@xxxxxxxxxx> wrote:
Use:
public string[] Split (
params char[] separator
)
to split your string on the asterisk as a first step.
Now you can enumerate over the string array splitting out your identifiers
and data strings. You could use a StringBuilder to build what ever you want
to output.
Now you can use:
public bool StartsWith (
string value
)andpublic string Substring (
int startIndex
)e.g.StringBuilder sb = new StringBuilder();
foreach (string s in strArray)
{
if (s.StartsWith("CZ")
{
sb.Append("CZ");
sb.Append(s.Substring(2));
}
else
{
sb.Append("fuuu");
sb.Append(s.Substring(4))
}
}return sb.ToString();
I'm sure there's an easier way using a Regex, but I can't be bothered to
puzzle it out.
HTH
Peter
<jayluc...@xxxxxxxxx> wrote in messagenews: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
.
- References:
- Regex repeating capture
- From: jaylucier
- Re: Regex repeating capture
- From: Peter Bradley
- Regex repeating capture
- Prev by Date: Re: parametize the "is" keyword
- Next by Date: Programatically uninstall/install a service.
- Previous by thread: Re: Regex repeating capture
- Next by thread: Re: Regex repeating capture
- Index(es):
Relevant Pages
|