jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes string.replaceall() and java.util.regex.Pattern/Matcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string.replaceall() and java.util.regex.Pattern/Matcher" Watch "string.replaceall() and java.util.regex.Pattern/Matcher" New topic
Author

string.replaceall() and java.util.regex.Pattern/Matcher

joe nesbitt
Greenhorn

Joined: Dec 05, 2009
Posts: 17
Hi all,

i have a regex that checks if the content between the 5th and 6th occurence of | is "" as follows:

(TEST\\|[||]*\\|\\|[||]*\\|[||]*\\|)\"\"")

It works fine with string.replaceall(). But when same pattern is used with java.util.regex.Pattern and Matcher classes, Matcher.find() is always false. Does it mean that the above regex must not contain the match part, I tried that but in vain.

Could someone, show me as how to use the above regex in combination of Pattern and Match classes.

Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

String.replaceAll uses Pattern/Matcher in the background:
In Matcher:
So if String.replaceAll is working, then you're doing something wrong when using Pattern/Matcher.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: string.replaceall() and java.util.regex.Pattern/Matcher
 
It's not a secret anymore!