Regular expression not accepted in Java
Hola,
I´m trying to compile the following Java RegEx expression:
As you can see, it is very simple. In
egrep (UNIX utility) it works correctly, and in Notepad++, too.
This is the code that I have wrote to test it:
Code:
public class Backreferencing {
public static void main( String[] args ) {
try {
BufferedReader br = new BufferedReader( new FileReader( "regex-files/ch01/ex12.backreferencing.txt" ) );
String currentLine = null;
Pattern p = Pattern.compile( "\\<the +the\\>" );
while( ( currentLine = br.readLine() ) != null){
Matcher m = p.matcher(currentLine);
while( m.find() ){
System.out.println( currentLine );
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ex12.backreferencing.txt file contents:
She likes to eat chocolate. But the the chocolate is not good in exceeds.
Some idea or suggestion?
Thanks in advance.
Saludos,
Re: Regular expression not accepted in Java
did you read Pattern (Java Platform SE 6) ?
There is no \< or \> (start and end of word) in java! for word boundaries in regex in java you can use \b -> "\\bthe +the\\b"
Re: Regular expression not accepted in Java
Quote:
Originally Posted by
eRaaaa
did you read
Pattern (Java Platform SE 6) ?
There is no \< or \> (start and end of word) in java! for word boundaries in regex in java you can use \b -> "\\bthe +the\\b"
You said the key word (start and end of word). Thanks for it.
Sorry, but I am just starting with RegEx.
Thanks a lot for your help, eRaaaa!