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 Regex Engine question - Conditional Statements?

807591Jun 4 2008 — edited Jun 4 2008
Hi guys

I am having difficulty writing a conditional regular expression using Java regex implementation.

I have read that the java regex engine does not implement the conditional statement that is present in Perls regex engine.
for example in Perl you can have (?(?=regex)then|else)

The application can recieve a string in anyone of these 4 formats and a single regular expression is needed to match MyMatch in each instance.

1. Blade=0-3,MyMatch=1
2. Blade=0-3,MyMatch.attribute=1
3. MyMatch=1
4. MyMatch.attribute=1

I can do this with the following regular expression using the Perl engine.
(?(.+,).+,([^\.]*).*=.+|([^\.]*).*=.+)

But I am completely stumped as to how I can do it with Java as the conditional statement does not seem to be implemented.

Any help greatly appreciated.
Steve
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2008
Added on Jun 4 2008
8 comments
1,575 views