I’m trying to make a case insensitive regular expression for my shipping section that catches all postcodes which start with GY1 – GY9 (single figures only). So far, it catches all gy postcodes, not just 1-9. Here is what I have so far:
^[gG][yY][1-9]{1}
Any ideas?
Edit:
I used the following regex based on stema’s answer below:
^[gG][yY][1-9]\s?[1-9][a-zA-Z]{2}$
Try this
Your regex matches because there can be anything following your digit.
I use the negative lookahead assertion
(?!\d)to ensure that there is not a digit after your[1-9].The flag
iat the end makes the regex matching case insensitive, so no need for[gG][yY]See it here on Regexr
Edit:
When the second part can has only 1 leading digit you can try this
See it here on Regexr
Means starts with “GY” then a digit from 1-9, followed by an optional space, then another digit and two letters.