Return Data Regex Doesn't Isolate - Yikes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Garibaldi

    Return Data Regex Doesn't Isolate - Yikes

    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

    000000000000000 00000
    200~11111111111 111111
    222222222222222 22222222222222
    3333333333333
    200~44444444444 4444444444444
    555555555555555 555555555555555 555
    66666666
    200~77777777777 7777777
    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


  • Justin Rogers

    #2
    Re: Return Data Regex Doesn't Isolate - Yikes

    I had some rather large explanation of how to do it procedurally, but then I
    thought,
    "Justin, get off your arse and write some regular expression magic!". So here
    you go.

    using System;
    using System.Text.Reg ularExpressions ;

    public class SuperRegex {
    private static string stuff =
    @"0000000000000 0000000
    200~11111111111 111111
    222222222222222 22222222222222
    3333333333333
    200~44444444444 4444444444444
    555555555555555 555555555555555 555
    66666666
    200~77777777777 7777777
    888888888888";

    private static void Main(string[] args) {
    Regex regex = new Regex("(?ms)(?: \\A|^200~)(.*?) (?=^200~|\\Z)") ;
    MatchCollection matches = regex.Matches(s tuff);
    for(int i = 0; i < matches.Count; i++) {
    Console.WriteLi ne();
    Console.WriteLi ne(matches[i].Value);
    Console.WriteLi ne();
    }
    }
    }


    --
    Justin Rogers
    DigiTec Web Consultants, LLC.
    Blog: http://weblogs.asp.net/justin_rogers


    "Garibaldi" <ty_92648 AT hotmail.com> wrote in message
    news:%238ChU$9H EHA.3144@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > 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
    >
    > 000000000000000 00000
    > 200~11111111111 111111
    > 222222222222222 22222222222222
    > 3333333333333
    > 200~44444444444 4444444444444
    > 555555555555555 555555555555555 555
    > 66666666
    > 200~77777777777 7777777
    > 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
    >
    >[/color]


    Comment

    • Brian Davis

      #3
      Re: Return Data Regex Doesn't Isolate - Yikes


      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




      "Garibaldi" <ty_92648 AT hotmail.com> wrote in message
      news:%238ChU$9H EHA.3144@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > 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[/color]
      string[color=blue]
      > but before the start of the next 200~. Here's the regex expression and[/color]
      test[color=blue]
      > data:
      >
      > (?ms)^200~(.*?) (?=^200~)
      >
      > Here's some test data
      >
      > 000000000000000 00000
      > 200~11111111111 111111
      > 222222222222222 22222222222222
      > 3333333333333
      > 200~44444444444 4444444444444
      > 555555555555555 555555555555555 555
      > 66666666
      > 200~77777777777 7777777
      > 888888888888
      >
      > The regex will return 200~ plus all ones, twos, threes as a group then[/color]
      200~[color=blue]
      > 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[/color]
      all[color=blue]
      > 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
      >
      >[/color]


      Comment

      • Garibaldi

        #4
        Re: Return Data Regex Doesn't Isolate - Yikes

        Thanks, Brian. Appreciate your suggestion. I'll give a shot.


        "Brian Davis" <brian@knowdotn et.nospam.com> wrote in message
        news:OPXlUSDIEH A.2480@tk2msftn gp13.phx.gbl...[color=blue]
        >
        > 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$9H EHA.3144@TK2MSF TNGP10.phx.gbl. ..[color=green]
        > > 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[/color][/color]
        all[color=blue][color=green]
        > > data from the start of a string begining with 200~ to the end of the[/color]
        > string[color=green]
        > > but before the start of the next 200~. Here's the regex expression and[/color]
        > test[color=green]
        > > data:
        > >
        > > (?ms)^200~(.*?) (?=^200~)
        > >
        > > Here's some test data
        > >
        > > 000000000000000 00000
        > > 200~11111111111 111111
        > > 222222222222222 22222222222222
        > > 3333333333333
        > > 200~44444444444 4444444444444
        > > 555555555555555 555555555555555 555
        > > 66666666
        > > 200~77777777777 7777777
        > > 888888888888
        > >
        > > The regex will return 200~ plus all ones, twos, threes as a group then[/color]
        > 200~[color=green]
        > > plus all fours, fives, sixes as a group
        > >
        > > Problem
        > > ---------
        > > Now I need to do the reverse. I need to return all the data the[/color][/color]
        preceding[color=blue][color=green]
        > > regex doesn't return. IOW, I need to return all the zeros and 200~ plus[/color]
        > all[color=green]
        > > 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
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Garibaldi

          #5
          Re: Return Data Regex Doesn't Isolate - Yikes

          Got it, thanks, Justin!

          "Justin Rogers" <Justin@games4d otnet.com> wrote in message
          news:O83SuDBIEH A.2556@TK2MSFTN GP12.phx.gbl...[color=blue]
          > I had some rather large explanation of how to do it procedurally, but then[/color]
          I[color=blue]
          > thought,
          > "Justin, get off your arse and write some regular expression magic!". So[/color]
          here[color=blue]
          > you go.
          >
          > using System;
          > using System.Text.Reg ularExpressions ;
          >
          > public class SuperRegex {
          > private static string stuff =
          > @"0000000000000 0000000
          > 200~11111111111 111111
          > 222222222222222 22222222222222
          > 3333333333333
          > 200~44444444444 4444444444444
          > 555555555555555 555555555555555 555
          > 66666666
          > 200~77777777777 7777777
          > 888888888888";
          >
          > private static void Main(string[] args) {
          > Regex regex = new Regex("(?ms)(?: \\A|^200~)(.*?) (?=^200~|\\Z)") ;
          > MatchCollection matches = regex.Matches(s tuff);
          > for(int i = 0; i < matches.Count; i++) {
          > Console.WriteLi ne();
          > Console.WriteLi ne(matches[i].Value);
          > Console.WriteLi ne();
          > }
          > }
          > }
          >
          >
          > --
          > Justin Rogers
          > DigiTec Web Consultants, LLC.
          > Blog: http://weblogs.asp.net/justin_rogers
          >
          >
          > "Garibaldi" <ty_92648 AT hotmail.com> wrote in message
          > news:%238ChU$9H EHA.3144@TK2MSF TNGP10.phx.gbl. ..[color=green]
          > > 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[/color][/color]
          all[color=blue][color=green]
          > > data from the start of a string begining with 200~ to the end of the[/color][/color]
          string[color=blue][color=green]
          > > but before the start of the next 200~. Here's the regex expression and[/color][/color]
          test[color=blue][color=green]
          > > data:
          > >
          > > (?ms)^200~(.*?) (?=^200~)
          > >
          > > Here's some test data
          > >
          > > 000000000000000 00000
          > > 200~11111111111 111111
          > > 222222222222222 22222222222222
          > > 3333333333333
          > > 200~44444444444 4444444444444
          > > 555555555555555 555555555555555 555
          > > 66666666
          > > 200~77777777777 7777777
          > > 888888888888
          > >
          > > The regex will return 200~ plus all ones, twos, threes as a group then[/color][/color]
          200~[color=blue][color=green]
          > > plus all fours, fives, sixes as a group
          > >
          > > Problem
          > > ---------
          > > Now I need to do the reverse. I need to return all the data the[/color][/color]
          preceding[color=blue][color=green]
          > > regex doesn't return. IOW, I need to return all the zeros and 200~ plus[/color][/color]
          all[color=blue][color=green]
          > > 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
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...