Steve
I want to know what is the Regex to read a String of Characters exactly to the point where I find a particular word; at which point the rest of the String should be discarded Including the word. Could somebody please help me?
Jose Campana wrote:
Nice Solution Steve Luke ! it works, however, I would like to stick to using Regex in this case. Could someone suggest something a little more specific, I'm really lost in terms of anything related to building Regular expressions. What is a Group?, I think a year ago I knew.
Jose Campana wrote:Unfortunately, I was asked to do it with Regex....
Please be so kind to show me how the pros do it....
Sincerely,
Jose
Steve
Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Jose Campana wrote:
You're the eminence of Java Programming as far as I'm concerned, and to address your doubts I'll say that I was asked to do it in that way because apparently the architect here thought it was a much cleaner, and efficient solution to 'look-up' for portions of text in a String. the idea is to do it 'SQL-style'. However I think I'll perform this task using a simple String.split(). that was the final agreement. And you're right, I shouldn't be afraid of telling my bosses what I think is the most adequate path to solve a problem.
Jose Campana wrote:Hello, Rob.
You're the eminence of Java Programming as far as I'm concerned
Henry Wong wrote:IMHO, using regexes, in many ways, in "much cleaner" and "efficient solution". However, this assumes that you actually know regular expressions. If you are not used to using regexes, it is just gobbly gook.
Here is the solution that you are looking for -- made it as simple (short) as I could.
Now.... Is this cleaner? Or is this globby gook?
Henry
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Henry Wong wrote:...
Here is the solution that you are looking for -- made it as simple (short) as I could.
...
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
and that can be a bit shortened by just doing:
Oh yes regexes are interesting, and now that I look at that one closer, I'm still convinced that even if I don't know If it looks clean or globby, It Sure looks Fancier!
Henry Wong wrote:...
And also recommend avoiding regex altogether until you have a better grasp of the concept. ...
Henry Wong wrote:...
I didn't even think of removing what I didn't...
Henry
Jose Campana wrote:...
Piet, I haven't tried your code yet, Does it work in the case where I would find more than one <and> in the String?
Jose Campana wrote:Because it actually doesn't matter; I want the regex to discard whatever comes Next from the first <and> including the first <and>.
...
Jose Campana wrote:Hey Piet !
How are you ? It Did ! It did actually clear things up. That's awesome, I had the time to review the regex codes, and it has been very beneficial to me, because now I have a more complete arsenal of statements at my disposal. As I said before, your contributions are invaluable. Keep up the fantastic work.
Good luck,
Sincerely,
Jose
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |