Skip to content

Index Submatch (${1}) does not work as expected #233

@oliverisaac

Description

@oliverisaac

Hello,

When I try to use a regex with an index submatch, the index submatch has an "off by two" behavior.

I would expect this to work:

Image

However, autolink is adding extra parenthesis around the regex, so instead I have to do this:

Image

(Note the ${3})

This can be reproduced using this sequence of commands:

/autolink add submatch
/autolink set submatch Pattern prefix/(.*)
/autolink set submatch Template final/${1}
/autolink test submatch prefix/hello

/autolink set submatch Template final/${3}
/autolink test submatch prefix/hello

I acknowledge I can use named submatch groups but the golang regex dialect isn't portable to the other languages we are using (ruby) so I'd like to use the numeric submatches instead.

Workarounds

  • Ruby doesn't support (?P<name>submatch) syntax for subgroups, but grep -P does
  • We can use the off-by-2 index, but it's unintuitive when writing the code and prone to error

This isn't a blocker for me, but figured I'd drop this here. At the very least, maybe we update the README so it calls out this unexpected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions