I’m trying to make this regex:
(?<=section)(.*?)(?=\#)
For these examples:
https://www.test.com/en/section/string-to-get#id=4949
https://www.test.com/en/section/string-to-get/page&2#id=4949
>Solution :
You need to use
(?<=section\/)([^\/#]*)
Or, just
section\/([^\/#]*)
and grab Group 1 value.
Here,
(?<=section\/)– a positive lookbehind that matches a location immediately preceded withsection/substring([^\/#]*)– Capturing group 1: zero or more chars other than/and#.
See the regex demo #1 and regex demo #2.
Depending on whether or not regex delimiters are required and if they are not /s you may use an unescaped /, (?<=section/)([^/#]*) and section/([^/#]*).