Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Mar 6, 2019
  • facebook
  • twitter
  • in
  • Email

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Escape Characters in Regular Expressions

In Java, characters as <([{\^-=$!|]})?*+.> cannot appear in a regular expression without being escaped.

For this, rely on the Pattern.quote() method as in the following example:

public static boolean contains(String t1, String t2) { 
return t1.matches(Pattern.quote(t2)); 
}

Now t2 can contain special characters.

Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
w3.org
w3.org