Re: Return Data Regex Doesn't Isolate - Yikes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Brian Davis (brian_at_knowdotnet.nospam.com)
Date: 04/12/04


Date: Sun, 11 Apr 2004 22:15:41 -0400


You could just call Regex.Replace with the same expression and an empty
string as the replacement if you didn't need to access any of the match
properties (index, groups, etc.).

Brian Davis
http://www.knowdotnet.com

"Garibaldi" <ty_92648 AT hotmail.com> wrote in message
news:%238ChU$9HEHA.3144@TK2MSFTNGP10.phx.gbl...
> Folks,
>
> I'm having a bad regex day and can sure use your help, please..
>
> I have a Regex expression that works fine. It's purpose is to isolate all
> data from the start of a string begining with 200~ to the end of the
string
> but before the start of the next 200~. Here's the regex expression and
test
> data:
>
> (?ms)^200~(.*?)(?=^200~)
>
> Here's some test data
>
> 00000000000000000000
> 200~11111111111111111
> 22222222222222222222222222222
> 3333333333333
> 200~444444444444444444444444
> 555555555555555555555555555555555
> 66666666
> 200~777777777777777777
> 888888888888
>
> The regex will return 200~ plus all ones, twos, threes as a group then
200~
> plus all fours, fives, sixes as a group
>
> Problem
> ---------
> Now I need to do the reverse. I need to return all the data the preceding
> regex doesn't return. IOW, I need to return all the zeros and 200~ plus
all
> the sevens and all the eights as a group. I want to execute "NOT
> (?ms)^200~(.*?)(?=^200~)"
>
> Sure could use a pointer to the correct starting point or any suggestion
> that will help me reach my goal.
>
> Thanks in advance
>
> ty_92648 AT hotmail.com
>
>



Relevant Pages

  • Re: Additional Functions for base classes.
    ... Unless you want to replace them all at the same time, using Regex is a very expensive operation to do single string replacements. ... You can use a regex to specify all of the characters that need to have somthign prefixed by grouping them into a characterset. ... The replacement patterns are a little different than you're used to, because it is possible to include the text you originally found. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Replace character
    ... Regex.Replace with a reasonable regex expression for valid email ... addresses should give a reasonable correct replacement. ... The second problem is that this identifies all emails on my string ... Second option is to use verbatim strings ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fastest way to search a string for the occurance of a word??
    ... but the OP's question was what's the "Fastest way to search a string ... in all the tests I did here, the Regex was by far superior. ... However, of course, if you've got new regular expressions all ... Sure - but just that extra Match object could be relevant if the search ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regular expression help
    ... Basically because if you remove everything that is optional in the regex below you end up with an empty regex: ... So the regex engine will try to match on every character in the string: ... , comma doesn't match, but the nothingness in front of it does. ... A quote followed by any sequence of characters that is not a quote, ...
    (microsoft.public.dotnet.framework)
  • Re: Replace character
    ... Capture the parts you want to keep in a named group and put them back into the replacement pattern $. ... looks back in your string and tries to find the pattern that is defined at the '...'. ... The funny thing is, that even though you search for something in your regex, it doesn't become part of the actual Match and therefore doesn't get replaced. ... Second option is to use verbatim strings in C# ...
    (microsoft.public.dotnet.languages.csharp)