Forum Discussion

Alfonso_Santia2's avatar
Icon for Altostratus rankAltostratus
Jan 17, 2023

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 check...
  • CA_Valli's avatar
    Jan 17, 2023

    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 as well as

    ^\/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