mock5c
asked on
Regular Expression to repeat matching in a phrase
I don't think my title for this question is very good. Hopefully people will notice this question.
If I have a phrase such as this: "You must be enrolled in the School of Business and be a student with junior or senior standing."
I'd like to use regexp to parse out "junior" and "senior". In this case, they are separated by "or", which can be tossed out. Here is my regexp so far:
/^You must be enrolled in the School of Business and be a student with\s*((?:junior|senior|( ?=\s*or\*) )).*\s*sta nding.$/g
I'm only getting "junior" for this.
If I manipulate it a little bit with this regexp:
/^You must be enrolled in the School of Business and be a student with\s*(((?:junior|senior) |(?=\s*or\ *))).*\s*s tanding.$/ g
I get:
junior
junior
Is there a way to get this result:
junior
senior
I will expect that I could possibly have junior or senior or junior and senior phrases and even through in freshman and/or sophomore. So I'm trying to parse out those tokens.
Another alternative would be to just grab the phrase, e.g.
junior or senior
junior and senior
sophomore or junior or senior
sophomore and junior or senior
etc.
So it would be something like ((?:freshman|sophomore|jun ior|senior |?=(?:and| or))
If I have the whole phrase, I can programatically split the string into tokens instead of having a regex return the individual tokens. I think either approach will work for me.
If I have a phrase such as this: "You must be enrolled in the School of Business and be a student with junior or senior standing."
I'd like to use regexp to parse out "junior" and "senior". In this case, they are separated by "or", which can be tossed out. Here is my regexp so far:
/^You must be enrolled in the School of Business and be a student with\s*((?:junior|senior|(
I'm only getting "junior" for this.
If I manipulate it a little bit with this regexp:
/^You must be enrolled in the School of Business and be a student with\s*(((?:junior|senior)
I get:
junior
junior
Is there a way to get this result:
junior
senior
I will expect that I could possibly have junior or senior or junior and senior phrases and even through in freshman and/or sophomore. So I'm trying to parse out those tokens.
Another alternative would be to just grab the phrase, e.g.
junior or senior
junior and senior
sophomore or junior or senior
sophomore and junior or senior
etc.
So it would be something like ((?:freshman|sophomore|jun
If I have the whole phrase, I can programatically split the string into tokens instead of having a regex return the individual tokens. I think either approach will work for me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> I'm using http://www.regexr.com/ to test.
That may be your problem.
/^You must be enrolled in the School of Business and be a student with\s*(junior)(?:\s*or\s* )(senior)\ s*standing .$/
That may be your problem.
/^You must be enrolled in the School of Business and be a student with\s*(junior)(?:\s*or\s*
ASKER