Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Regex

 
Vincent Tomas
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20999
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vincent Tomas
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My gosh. How did I missed that? Thanks Henry!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic