1

What is ?<> pattern in javascript regular expression?

Example:

/^github.com\/(?<root>[\w-]+)\/(?<repo>[\w-]+)\/(?<branch>[\w-]+)$/
  • According to rules of the [tag:regex] tag, you should also tag with the regexp engine or programming language you are using. Though we can guess in this case it is probably .NET or Ruby: the `(?...)` creates a named capture group. See the appropriate entry in the reference duplicate. – Amadan Mar 27 '23 at 06:36
  • @Amadan I'm using this with Javascript – Sunil Kumar Singh Mar 28 '23 at 05:52
  • 1
    Same in JavaScript: `"Take 42 apples".match(/(?\d+)/)?.groups?.num` should give you `"42"`, as the sequence of digits is captured in the group named `num`. – Amadan Mar 28 '23 at 06:25

1 Answers1

2

(?<>) specifies a named capture group. Depending on the RegEx engine you're working with this might have different results on the output you're getting, it might not even work at all. It basically defines the capture group (?<a>) to be named "a" which will (probably) be returned in your result set.