Reputation: 45
I want to build an if
statement which reads a url parameter and checks if it meets the following special pattern:
Single capital letter (A to E), followed by
Single capital letter (R, S, H, or T), followed by
One digit (1 or 2), followed by
Two digits (01 to 18), followed by
Two digits (01 to 60), followed by
Single capital letter (X or Y), followed by
Pair of float numbers separated by a comma (5.8234,11.231134)
Example of matching patterns:
AH20340X22.14,43.8241212
CT11154Y1.431212,11.413
ES10113X11.512341,55.134513
Upvotes: 0
Views: 100
Reputation: 5224
You cannot check if a number is "between 01 and 18" with a regular expression (finite state machine) so you have to cheat a bit.
So you will have to write:
Single capital letter (A to E) => [A-E]
Single capital letter (R, S, H, or T) => [RSHT]
One digit (1 or 2) => [12]
Two digits (01 to 18) => ([0][1-9]|[1][0-8])
Two digits (01 to 60) => ([0][1-9]|[1-5][0-9]|60)
Single capital letter (X or Y) => [XY]
Float number => [0-9]+(\.[0-9]+)?
Comma => ,
Float number => [0-9]+(\.[0-9]+)?
So you will end up with:
/[A-E][RSHT][12]([0][1-9]|[1][0-8])([0][1-9]|[1-5][0-9]|60)[XY][0-9]+(\.[0-9]+)?,[0-9]+(\.[0-9]+)?/
Upvotes: 1