Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex recursion captured string

I have a problem with a regex that has to capture a substring that it's already captured...

I have this regex:

(?<domain>\w+\.\w+)($|\/|\.)

And I want to capture every subdomain recursively. For example, in this string:

test1.test2.abc.def

This expression captures test1.test2 and abc.def but I need to capture: test1.test2 test2.abc abc.def

Do you know if there is any option to do this recursively?

Thanks!

like image 341
Dugalle Avatar asked Feb 03 '26 02:02

Dugalle


1 Answers

Maybe the following:

(\.|^)(?=(\w+\.\w+))

Go with capturing group 2

like image 141
JvdV Avatar answered Feb 04 '26 16:02

JvdV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!