Jump to content

need a good regex for "OR" structure


senca99

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/242942-need-a-good-regex-for-or-structure/
Share on other sites

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.

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.