Home > front end >  Regex - Named Group inside of a named group
Regex - Named Group inside of a named group

Time:11-21

I've created a regex that matches this the URL below but now I want to match the whole URL, capture it in a named group and capture the uid of the URL in another named group.

The example:

<"http://www.accounts.com/support/uid=swg1PM80378">

The expected outcome:

first group: http://www.accounts.com/support/uid=swg1PM80378
second group: swg1PM80378

My regex so far:

<"(?<link>.*(?<id>NOTHING IN HERE YET))">

With this regex I can match the whole URL and capture it in the named group but I want to expand the regex's functionality to also capture the uid of the link and capture it in the second group named

I've used the site https://regexr.com/ to create the regex, maybe it'll be of help.

CodePudding user response:

Try:

\"(?P<link>.*(?P<id>(?<=uid=).*))\"

Regex demo.


\" - match "

  • (?P<link>.*) - Match any number of characters into named group link

    • (?P<id>(?<=uid=).*) - Match any number of characters preceded witch uid= into named group link
  • \" - match "

  • Related