imperium2335 Posted December 17, 2011 Share Posted December 17, 2011 Hi, what is the regex for this: 'FR'+11 digits, the first and/or the second value can also be a character – e.g. FRXX999999999 I have tried ^([FR]{2})*(([A-Za-z0-9]{2}\d)){11}$ and a number of other things but I can't seem to get it right. Quote Link to comment https://forums.phpfreaks.com/topic/253366-regex-help/ Share on other sites More sharing options...
imperium2335 Posted December 17, 2011 Author Share Posted December 17, 2011 Hi, I figured it out. Here it is incase it helps anyone else: ^([FR]{2})*([A-Za-z0-9]{2}\d{9})$ Quote Link to comment https://forums.phpfreaks.com/topic/253366-regex-help/#findComment-1298781 Share on other sites More sharing options...
joe92 Posted December 17, 2011 Share Posted December 17, 2011 Wrong forum board By the way, that regex will allow for patterns such as RF99999999999, and also 99999999999. Characters don't need to go in character classes (the square brackets) and in your case shouldn't. The beginning of your regex says ([FR]{2})* That is searching for an F or an R, twice. So will match, FF, FR, RF and RR. You also say match this between zero and infinity times (the *). So it could also match '' or 'FFFRRRRRRRFRFRFFFRFRFR' - as that is F or R twice, eleven times (which is between zero and infinity). You see where I'm going with this right? You need to be matching a literal string at the beginning if it always begins with 'FR'. The regex you need is: ^FR[A-Za-z0-9]{2}\d{9}$ Hope this helps, Joe Quote Link to comment https://forums.phpfreaks.com/topic/253366-regex-help/#findComment-1298787 Share on other sites More sharing options...
imperium2335 Posted December 17, 2011 Author Share Posted December 17, 2011 Hi, you are right. I made your adjustments and it is perfect now! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/253366-regex-help/#findComment-1298791 Share on other sites More sharing options...
joe92 Posted December 17, 2011 Share Posted December 17, 2011 No problem. Don't forget to mark it as solved Quote Link to comment https://forums.phpfreaks.com/topic/253366-regex-help/#findComment-1298795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.