Regex for dynamic URI
Can anyone help on the regex for a dynamic uri, like:
where "7288EA75-5B4C-4931-A1F9-D185077CE5E7" is changing (dynamic)
I have checked other posts on regex with dynamic uri but did not find any that answers this question this is why
It's hard to do without setting boundaries,
\/main\/.*\/ is the easiest regex to write, it will match any character and any string length between the second and third slash characters. This has no delimiters anyways, so it will match https://test.foo.com/main/7288EA75-5B4C-4931-A1F9-D185077CE5E7/ as well as https://test.foo.com/lots/of/folders/deep/main/7288EA75-5B4C-4931-A1F9-D185077CE5E7/
^\/main\/.*\/ will perform faster because you're adding a "start of string"
^\/main\/.*\/$ is better if nothing comes after the dynamic part because you're adding an "end of string" delimiter
You can also go for better matches, if you can define a pattern in the dynamic data (like in Juergen_Mang suggestion) and/or if you know that the string is X characters long -- it's always best to use all of that information when setting the match conditions.
regex101 is a good tool to help you build it, you can paste strings that should and string that shoudn't match in the text box and see what your regex will be matching.
I've tested the ^\/main\/\w+-[\w-]+\/ syntax in example below, see what matches by yourself