i write a simple Rss Feed reader now i have this problem, in the item description i have the text but this text have this caracters <br/>
for example
“my dog
<br/>is black and he<br/>stay on table “
now i wont to clear the string from this caracters, i wirte this metod
private static String IsMatch(String s, String pattern) {
try {
Pattern patt = Pattern.compile(pattern);
Matcher matcher = patt.matcher(s);
return matcher.group();
} catch (RuntimeException e) {
return "Error";
} }
and
String regex ="[<br/>]";
theString2=IsMatch(theString,regex);
AppLog.logString(theString2);
but But this method return always Error. Can any one tell me what’s the problem?
best regads
Antonio
The problem is that you never invoke find() on your matcher. You must invoke find() before invoking group() (and test that find() returns true).
I am not sure of what your method
IsMatchis supposed to do. As it is, it will either return the match (ie,"<br/>", assuming you invokefind()before) either return"Error".Also, don’t put the brackets around
<br/>in your regexp, they are not needed.I wouls really consider using replace instead of regexp for your purposes:
As a recommendation, don’t catch an exception without logging the it. They provide valuable information that should not be hidden. It make debug really hard when a problem occurs.