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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.