I am trying to understand Pattern.quote using the following code:
String pattern = Pattern.quote("1252343% 8 567 hdfg gf^$545"); System.out.println("Pattern is : "+pattern);
outputs the result:
Pattern is : \Q1252343% 8 567 hdfg gf^$545\E
What is \Q and \E here? The description of the documentation states:
Returns the literal String pattern for the specified String .
This method creates a String that can be used to create a Pattern that matches the string s , as if it were a literal.
Metacharacters or escape sequences in the input sequence will not have special meaning.
But Pattern.quote the return type of the String , not a compiled Pattern .
Why is this method needed and what are some usage examples?
java regex pattern-matching
Prateek Mar 14 '13 at 12:27 2013-03-14 12:27
source share