Re: Splitting a string with Regex and keep the separator



* 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
.



Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • Re: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)
  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)