General Question

mistic84's avatar

How do I create a regular expression for a range?

Asked by mistic84 (254 points ) April 10th, 2012

I am separating a list into 2 groups by their first name. I used the regular expression ^[A-J] and ^[J-Z]. I found out there are a lot of “J” names. How do I create an expression that will do ^[A-Je]. The program I am using does not accept this as a valid expression.

Observing members: 0 Composing members: 0

6 Answers

Thammuz's avatar

What program are you using? Can you post the full code of the relevant expression?

Need more data.

funkdaddy's avatar

Something like this might work for you (tough to read without a monospace font)

^[A-I] | ^J[a-e]

Basically A through I or J with your range of next letters defined for each side. So the other side would look like

^[K-Z] | ^J[f-z]

You’ll need to account for pulling the whole string and for differences in case, but those weren’t part of your question so I’ll assume you’ve got those worked out elsewhere.

Good luck with the project.

dabbler's avatar

Per @Thammuz, what are you running ? sed? awk? PERL?

PhiNotPi's avatar

@funkdaddy Monospaced font is possible by appending a @ symbol at the beginning and end of each line you want monospaced. It works similar to * and _ but can only work on a line by line basis.
^[A-I] | ^J[a-e]

ratboy's avatar

^[A-I]
^J[a-e]+
^J[f-z]+
^[K-Z]

mistic84's avatar

Thanks all for the help! I was just creating one in sales genius split a list I was email blasting.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther