Regex Q (Another one)

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

    #1

    Regex Q (Another one)

    Could anyone tell me why the following do not match?

    ^ABC_\d{6}_\d{6 }$

    Should match(twice):

    ABC_123456_7891 23
    ABC_123456_7891 23

    It matches:
    ABC_123456_7891 23

    But not the double one.

    Regex options set are:

    RegexOptions.Ig noreCase | RegexOptions.Ig norePatternWhit espace |
    RegexOptions.Mu ltiline

    TIA

    JB
  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Regex Q (Another one)

    John B wrote:
    Could anyone tell me why the following do not match?
    >
    ^ABC_\d{6}_\d{6 }$
    >
    Should match(twice):
    >
    ABC_123456_7891 23
    ABC_123456_7891 23
    >
    It matches:
    ABC_123456_7891 23
    >
    But not the double one.
    >
    Regex options set are:
    >
    RegexOptions.Ig noreCase | RegexOptions.Ig norePatternWhit espace |
    RegexOptions.Mu ltiline
    If I read your description correct, then it does more sound as
    a problem with the code retrieving matches than with the regex.

    Try post the code.

    Arne

    Comment

    • Lucas Eagleton

      #3
      Re: Regex Q (Another one)

      Hi John,

      I may be wrong, but from my experience, if it was to match your double item,
      it should be (^ABC_\d{6}_\d{ 6}$)+

      meaning that it would allow that whole pattern one or more times as opposed
      to just once.

      - Lucas


      "John B" <jbngspam@yahoo .comwrote in message news:fn0meq$qu2 $1@aioe.org...
      Could anyone tell me why the following do not match?
      >
      ^ABC_\d{6}_\d{6 }$
      >
      Should match(twice):
      >
      ABC_123456_7891 23
      ABC_123456_7891 23
      >
      It matches:
      ABC_123456_7891 23
      >
      But not the double one.
      >
      Regex options set are:
      >
      RegexOptions.Ig noreCase | RegexOptions.Ig norePatternWhit espace |
      RegexOptions.Mu ltiline
      >
      TIA
      >
      JB

      Comment

      • John B

        #4
        Re: Regex Q (Another one)

        Lucas Eagleton wrote:
        Hi John,
        >
        I may be wrong, but from my experience, if it was to match your double
        item, it should be (^ABC_\d{6}_\d{ 6}$)+
        >
        meaning that it would allow that whole pattern one or more times as
        opposed to just once.
        >
        Hmm, I was under the impression that it would match _any_ instances
        (only the *and+ operators being greedy and eating the other matches
        would interfere).

        I am by no means an expert though and I tried the grouped one or more
        and it still didnt work.

        I eventually used (?:^|\r|\n)(?<a sn>abc_\d{6}_\d {6})(?:$|\r|\n) which
        worked, see reply to Arne for more.

        Thanks for your help.

        John
        - Lucas
        >
        >
        "John B" <jbngspam@yahoo .comwrote in message
        news:fn0meq$qu2 $1@aioe.org...
        >Could anyone tell me why the following do not match?
        >>
        >^ABC_\d{6}_\d{ 6}$
        >>
        >Should match(twice):
        >>
        >ABC_123456_789 123
        >ABC_123456_789 123
        >>
        >It matches:
        >ABC_123456_789 123
        >>
        >But not the double one.
        >>
        >Regex options set are:
        >>
        >RegexOptions.I gnoreCase | RegexOptions.Ig norePatternWhit espace |
        >RegexOptions.M ultiline
        >>
        >TIA
        >>
        >JB
        >

        Comment

        • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

          #5
          Re: Regex Q (Another one)

          John B wrote:
          Arne Vajhøj wrote:
          >A bit of experimentation shows that:
          >>
          >matcher.Matche s("ABC_123456_7 89123\nABC_1234 56_789123")
          >>
          >will find 2 matches.
          >>
          >But it is not obvious to me why \n is the proper line
          >delimiter and not \r\n.
          >>
          >Maybe someone with more regex knowledge than me can
          >explain it.
          >
          Ahh, I see.
          Hmm, that is kind of odd, I would have thought the system "New Line"
          variable would be used (\r\n for windows obviously)
          Me too.

          But ...

          Arne

          Comment

          • henon

            #6
            Re: Regex Q (Another one)

            On Jan 21, 1:42 am, John B <jbngs...@yahoo .comwrote:
            Lucas Eagleton wrote:
            Hi John,
            >
            I may be wrong, but from my experience, if it was to match your double
            item, it should be (^ABC_\d{6}_\d{ 6}$)+
            >
            meaning that it would allow that whole pattern one or more times as
            opposed to just once.
            >
            Hmm, I was under the impression that it would match _any_ instances
            (only the *and+ operators being greedy and eating the other matches
            would interfere).
            >
            yes + and * are greedy but you can make them not greedy by appending
            a ? like this:

            new Regex("#.+?#") matched against "#hello # world#" would give
            "#hello #"
            while new Regex(".+") would return the match "#hello # world#"

            hth,
            -- henon

            --------------

            Comment

            • henon

              #7
              Re: Regex Q (Another one)

              On Jan 21, 12:10 pm, henon <meinrad.rech.. .@gmail.comwrot e:
              while new Regex(".+") would return the match "#hello # world#"
              correction: while new Regex("#.+#") would return the match "#hello #
              world#"

              Comment

              Working...