Re: Splitting a string with Regex and keep the separator
- From: Jesse Houwing <jesse.houwing@xxxxxxxxxxxxxxxx>
- Date: Tue, 05 Jun 2007 09:44:25 +0200
* nagar@xxxxxxxxxxxxxxxx wrote, On 5-6-2007 9:00:
Thanks. I'll try that code. Just to explain things better, I don't
need to create an output string. I need to convert the strings to an
array of keycodes to send text. So I just need to have a list of
tokens (and know if they are normal text or #KeyVal) and treat them
differently.
I'll test the code and let you know.
Thanks.
Andrea
Ok, I think I get where you're going. Try this:
Regex rx2 = new Regex(@"(?<keyval>#\w+\(\w+\))|(?<other>((?!#\w+\(\w+\)).)*)",
RegexOptions.None);
Matches ms = rx2.Matches("input");
foreach (Match m in ms)
{
if (m.Groups["keyval"].Success)
{
ManupulateKeyVal(m.Groups["keyval"].Value);
}
else if (m.Groups["other"].Success)
{
ManupulateOther(m.Groups["other"].Value);
}
}
That should work best. I thought you were creating a new string at first ;)
Jesse
.
- Follow-Ups:
- Re: Splitting a string with Regex and keep the separator
- From: nagar@xxxxxxxxxxxxxxxx
- Re: Splitting a string with Regex and keep the separator
- From: nagar@xxxxxxxxxxxxxxxx
- Re: Splitting a string with Regex and keep the separator
- From: nagar@xxxxxxxxxxxxxxxx
- Re: Splitting a string with Regex and keep the separator
- References:
- Splitting a string with Regex and keep the separator
- From: nagar@xxxxxxxxxxxxxxxx
- RE: Splitting a string with Regex and keep the separator
- From: Walter Wang [MSFT]
- Re: Splitting a string with Regex and keep the separator
- From: nagar@xxxxxxxxxxxxxxxx
- Splitting a string with Regex and keep the separator
- Prev by Date: C# DatePart() ?
- Next by Date: Re: Problem with creating classes as runtime - PLEASE HELP
- Previous by thread: Re: Splitting a string with Regex and keep the separator
- Next by thread: Re: Splitting a string with Regex and keep the separator
- Index(es):
Relevant Pages
|