Regex

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

    Regex

    Hello,
    I have a Regex:
    Regex regex = new Regex(@"22 22 22 22 22 22 22 22 22 22(?
    <centervalue>.+ )33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
    33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");

    Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
    I want the centervalue to start after ALL of the "22"'s but this is
    not happening.
    Once it see's the 10 sets it starts there, but I want it to start at
    the end, no matter how many sets.
    Any suggestions?
    Thanks,
    Mike
  • =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?=

    #2
    RE: Regex

    You want to specificy at least 10 repeats like this
    Regex regex = new Regex(@"(22 ){10,}(?
    <centervalue>.+ )(33 ){minimum allowable number,}");

    I think that will do it.
    If you enclose something in curly braces and follow it by the following
    strings, you will get the following number of matches (from C# in a Nutshell
    edition something)
    * Any number of matches (including zero)
    + At least 1 match
    ? Exactly 1 match
    {n} Exactly n matches
    {n,} At least n matches
    {n,m} At least n matches, No more than m matches


    Ethan



    "AMP" wrote:
    Hello,
    I have a Regex:
    Regex regex = new Regex(@"22 22 22 22 22 22 22 22 22 22(?
    <centervalue>.+ )33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
    33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");
    >
    Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
    I want the centervalue to start after ALL of the "22"'s but this is
    not happening.
    Once it see's the 10 sets it starts there, but I want it to start at
    the end, no matter how many sets.
    Any suggestions?
    Thanks,
    Mike
    >

    Comment

    • AMP

      #3
      Re: Regex

      On Apr 2, 10:29 am, Ethan Strauss
      <EthanStra...@d iscussions.micr osoft.comwrote:
      You want to specificy at least 10 repeats like this
            Regex regex = new Regex(@"(22 ){10,}(?
       <centervalue>.+ )(33 ){minimum allowable number,}");
      >
      I think that will do it.
      If you enclose something in curly braces and follow it by the following
      strings, you will get the following number of matches (from C# in a Nutshell
      edition something)
      *                      Any number of matches (including zero)
      +                      At least 1 match
      ?                      Exactly 1 match
      {n}                   Exactly n matches
      {n,}                 At least n matches
      {n,m}              At least n matches, No more than m matches
      >
      Ethan
      >
      >
      >
      "AMP" wrote:
      Hello,
      I have a Regex:
                  Regex regex = new Regex(@"22 22 22 22 22 22 2222 22 22(?
      <centervalue>.+ )33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
      33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");
      >
      Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
      I want the centervalue to start  after ALL of the "22"'s but this is
      not happening.
      Once it see's the 10 sets it starts there, but I want it to start at
      the end, no matter how many sets.
      Any suggestions?
      Thanks,
      Mike- Hide quoted text -
      >
      - Show quoted text -
      I'm getting:
      "parsing \"(22 ){10,}(? <centervalue>.+ )(33 ){10,}\" - Unrecognized
      grouping construct."

      Mike

      Comment

      • =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?=

        #4
        Re: Regex

        There is an extra space after your question mark and before the less than

        should be
        (22 ){10,}(?<center value>.+)(33 ){10,}
        not
        (22 ){10,}(? <centervalue>.+ )(33 ){10,}


        At least this takes care of the parsing error. I have not tested it for real
        functionality.
        Ethan

        "AMP" wrote:
        On Apr 2, 10:29 am, Ethan Strauss
        <EthanStra...@d iscussions.micr osoft.comwrote:
        You want to specificy at least 10 repeats like this
        Regex regex = new Regex(@"(22 ){10,}(?
        <centervalue>.+ )(33 ){minimum allowable number,}");

        I think that will do it.
        If you enclose something in curly braces and follow it by the following
        strings, you will get the following number of matches (from C# in a Nutshell
        edition something)
        * Any number of matches (including zero)
        + At least 1 match
        ? Exactly 1 match
        {n} Exactly n matches
        {n,} At least n matches
        {n,m} At least n matches, No more than m matches

        Ethan



        "AMP" wrote:
        Hello,
        I have a Regex:
        Regex regex = new Regex(@"22 22 22 22 22 22 22 22 22 22(?
        <centervalue>.+ )33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
        33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");
        Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
        I want the centervalue to start after ALL of the "22"'s but this is
        not happening.
        Once it see's the 10 sets it starts there, but I want it to start at
        the end, no matter how many sets.
        Any suggestions?
        Thanks,
        Mike- Hide quoted text -
        - Show quoted text -
        >
        I'm getting:
        "parsing \"(22 ){10,}(? <centervalue>.+ )(33 ){10,}\" - Unrecognized
        grouping construct."
        >
        Mike
        >

        Comment

        • =?Utf-8?B?S0g=?=

          #5
          RE: Regex

          How about:

          string str = "22 22 22 22 22 22 My Value 33 33 33 33 33 33 33";

          int start = str.LastIndexOf (" 22") + 3;
          int end = str.IndexOf(" 33);

          // Now you have the start and end locations of the value you're looking for
          and can use SubString to parse it out, or a RegEx if you need more complex
          parsing logic for it.

          HTH


          "AMP" wrote:
          Hello,
          I have a Regex:
          Regex regex = new Regex(@"22 22 22 22 22 22 22 22 22 22(?
          <centervalue>.+ )33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
          33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");
          >
          Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
          I want the centervalue to start after ALL of the "22"'s but this is
          not happening.
          Once it see's the 10 sets it starts there, but I want it to start at
          the end, no matter how many sets.
          Any suggestions?
          Thanks,
          Mike
          >

          Comment

          Working...