quote(String) method of a Pattern class used to returns a literal pattern String for the specified String passed as parameter to method.This method produces a String equivalent to s that can be used to create a Pattern. Metacharacters or escape sequences in the input sequence will be given no special meaning. If you compile the value returned by the quote method, you’ll get a Pattern which matches the literal string that you passed as a parameter to method.\Q and \E mark the beginning and end of the quoted part of the string.
public static String quote(String s)
Parameters: This method accepts a single parameter s which represents the string to be literalized.
Return value: This method returns a literal string replacement for String s.
Below programs illustrate the quote() method:
found the Regex in text:ee starting index:1 and ending index:3 found the Regex in text:ee starting index:9 and ending index:11
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.