dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 6, 2019

WEBINAR:

On-Demand

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


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
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date