Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.regex question: "OR" order matters?

807606Feb 6 2007 — edited Feb 6 2007
I have a large regex of several tokens or'd together. Here's an example: ^(CH|CHAP)

When I run it against my input string, I want it to match against the largest possible token in the or'd list. So here are examples:

"Input String" | Match
"CHA" | CH
"CHAPTER" | CHAP

Is there a way to do this without ordering the list of tokens that gets or'd together? Currently, it looks like it's using the first match that fits (in this example, "CHAPTER" would match on CH first and ignore CHAP).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2007
Added on Feb 6 2007
10 comments
165 views