Sunday, 2 November 2014

Pattern.LITERAL

Treat the expression as a sequence of literal characters, ignoring the normal regular expression escapes.

import java.util.regex.*;

public class RegExHarness {
    static Pattern pattern = Pattern.compile("\\d\\d\\d", Pattern.LITERAL);
    static Matcher matcher; 
          
    public static void main(String[] args) {
        String data = "\\d\\d\\d";

        RegExHarness obj = new RegExHarness();

        matcher = pattern.matcher(data);
        
        while (matcher.find()) {
            System.out.println(matcher.group());
 }
    }
}

Output
\d\d\d

If you don't specify 'Pattern.LITERAL' then '\d\d\d' match 3 digits.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment