senca99 Posted July 27, 2011 Share Posted July 27, 2011 Hey everyone! I can do some basic regexing but I don't really have a clue for this one. I want to create a regex that checks a user inputfield and it can only be this: 4 34 535 4a 55C 997G Only these 6 matches, an int, 2 ints, 3 ints, 1 int and a char, 2 ints and a char or 3 ints and a char. Not minding caps but it cannot be more then these 6. Something like "anintORtwointsORthreeintsORoneintandacharOR..." you get the point . The OR's are bugging me because I can't find a single line regex for it. Can anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/ Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 if they are all separated by an OR... why don't you use explode? $array = explode("OR", $string); Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1247871 Share on other sites More sharing options...
senca99 Posted July 27, 2011 Author Share Posted July 27, 2011 Thats not quite what I ment. The user input is only one of the 6 possibilities. They don't have to be what I wrote down but it just has to be int(s) that can be followed by a char. The user input is a housenumber. That could be any of the 6 combinations I wrote down. Characters stands for the mailbox number in flats. Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1247877 Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 now im confused, so "OR" isn't actually in your string like you have shown above? Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1247879 Share on other sites More sharing options...
senca99 Posted July 27, 2011 Author Share Posted July 27, 2011 Sorry if I wasn't clear. The line I gave was kindoff a pseudoregex. The bottomline is that it has to check for one of 6 possible combinations. For instance a person could live at number 66. The regex should check wether it is a valid housenumber according to the 6 possible combinations of ints and a char I gave. Thats why I used OR's to try and clearify what I ment. I guess in ugly terms that would give a pseudoregex like this: ^[1-9]$ OR ^[1-9][0-9]$ OR ^[1-9][0-9]{2}$ OR ^[1-9][A-Za-z]$ OR ^[1-9][0-9][A-Za-z]$ OR ^[1-9][0-9]{2}[A-Za-Z]$ I'm hoping that makes it more clear. Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1247884 Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 in regex the pipe symbol " | " is use as an OR statement Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1247886 Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 You don't need an OR $expression = '/^[0-9]{1,3}[a-z]{0,1}$/i'; Looks for 1-3 digits, followed by 0 or 1 letters Quote Link to comment https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/#findComment-1248004 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.