I'd like to put together REGEX for the string:
/maps/basic/5/16/12.png?key=xxx
What I am trying to achieve here is, that my condition will be TRUE IF the string (URI) will contain 3 numbers after 2 words:
/word/word/number/number/number*
CodePudding user response:
You can use the following pattern:
^(\/[a-zA-Z] \/[a-zA-Z] \/[0-9] \/[0-9] \/[0-9] )(\S.*)$
The result of your example would be:
- Group 1 match:
/maps/basic/5/16/12
- Group 2 match, the rest of the string:
.png?key=xxx
CodePudding user response:
Try this:
^\/[a-zA-Z] \/[a-zA-Z] \/\d \/\d \/\d .*
^ mathes the beginning of the string
\/[a-zA-Z] matches the first word
\/[a-zA-Z] matches the second word
\/\d \/\d \/\d matches the three numbers
.* matches anything after the numbers
This matches the url only if it begins with two words and is followed by three (or more ) words with anything after that.
Test here: https://regex101.com/r/mjWNUb/1