This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java Regex Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java Regex" Watch "Java Regex" New topic
Author

Java Regex

Vincent Tomas
Greenhorn

Joined: Jan 16, 2007
Posts: 15
Hello everyone,

I am new at regex and I have read several tutorials but I still can't find my answer, which is, is there a way to parse using 2 different patterns?

For example,


Sorry for being vague. To explain it in sentences, I am parsing source (.*cpp) files and I am trying to find the following:



Sounds easy, however, some source files have it like the following:



Is there anyway that I could search on two patterns?

Thank you for any help.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16687
    
  19

You can build a pattern from 2 patterns using the logical OR operator.

X|Y means match either X or Y, and if you use groups...

"(some regular expression)|(another regular expression)" will match either expression.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vincent Tomas
Greenhorn

Joined: Jan 16, 2007
Posts: 15
My gosh. How did I missed that? Thanks Henry!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Regex
 
Similar Threads
Read log file from date to date as one object
Regular Expression pattern search is throwing "java.lang.IllegalStateException"
I don't think I understand how Regular Expression works!
Problems with Matcher objects and the last line of a file
modifying an input file based on pattern matching