• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pattern Matching Question  RSS feed

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The code below works for doing pattern matching. Wondering if there would be a better way where I do not have to create separate Pattern and Matcher objects the way I have it now.
Here's the code -


Thanks!
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wondering if there would be a better way where I do not have to create separate Pattern and Matcher objects the way I have it now.


The string class has some convenience methods for regex. Under the covers, it still does create the pattern and matcher objects, but it will make your code shorter -- for example, the string class has a matches() method that will take a regex.

Henry
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,

Thanks for your suggestion. In the line of using Pattern do you think the following code change would be an alternative of what I wanted?


 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!