Is it possible to capture part of one capture group into a second capture group?

Example:

blah blah href='http://www.domain.com/keyid=432' blah blah blah blah

So if I use a regex like

href='(.*)' 

which captures the URL in group 1, but is it also possible to capture the key "432" in the second group? I am sure there is a way to achieve this, but I am still regex noob.

+3
source share
2 answers

Yes, you can group capture groups:

href='(.*/keyid=([0-9]+))' 
+3
source

Yes, capture groups can contain other capture groups.

But you really need to be much more careful with using regular expressions in HTML than very close to anyone who has ever been. There is one pair of , and heres another .

, , , , , , .

+1

Source: https://habr.com/ru/post/1777108/


All Articles