Uploaded image for project: 'named-regexp'
  1. named-regexp
  2. REGEX-2

Unnamed capture groups are broken

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.2
    • Labels:
      None

      Description

      Some uses of regexp patterns that include an unnamed capture group before a named one seems to cause the index of named groups to get out of sync (no longer retrieve proper matched value)

      eg: regular expression 'a(a|c)(?<named>b)'
      applied to input "acb" (no quotes)

      causes the function matcher.group("named") to return the value "c" instead of the expected value "b".

      Upon further inspection, it appears that the group name extractor function marks the group "named" as having index '1', by inserting it at the front of the list, but since the underlying regexp has '(a|c)' marked as group '1', and the "named" group marked as group '2', I can see that this is why the indices are out of sync.

      A workaround is to simply make all unnamed groups unmatching, ie using (?:) instead of ().

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tony19 Anthony Trinh [Administrator]
                Reporter:
                Anonymous
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day
                  1d

                    Who's Looking?