How do I create a regular expression for a range?
Asked by
mistic84 (
274)
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
What program are you using? Can you post the full code of the relevant expression?
Need more data.
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.
Per @Thammuz, what are you running ? sed? awk? PERL?
@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]
^[A-I]
^J[a-e]+
^J[f-z]+
^[K-Z]
Thanks all for the help! I was just creating one in sales genius split a list I was email blasting.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.