| Author |
regular expression regex to replace contains()
|
jay vas
Ranch Hand
Joined: Aug 30, 2005
Posts: 407
|
|
Hi ... how can I replace multiple "contains" calls with a regex in java ? i.e. Please let me know... I think this will be usefull for a lot of intermediate regex users...
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
Jay, There might be a simpler way to do it, but this works: I think the contains approach is clearer though.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
jay vas
Ranch Hand
Joined: Aug 30, 2005
Posts: 407
|
|
|
There has to be a simpler way...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
Originally posted by jay vas: There has to be a simpler way...
I agree with Jeanne that contains() will always be simpler than a regex.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by jay vas: There has to be a simpler way...
How do you come to that conclusion?
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
|
My note about a simpler way was more that I didn't spend any time tuning the reg exp. I wrote the first thing I thought of that is equivalent. In practice, I would just use contains. There is no reason to believe the reg exp version would be more efficient anyway. So why sacrifice readability?
|
 |
 |
|
|
subject: regular expression regex to replace contains()
|
|
|