Menu
Question Index
...

What will be the output of the following program?

import java.util.regex.*;

public class Matches {
    public static void main(String args[]) {
        reusePatternMethodExample();
    }
    public static void reusePatternMethodExample() {
        Pattern pat = Pattern.compile("\\d");
        Matcher m = pat.matcher("5");
        boolean yes = m.matches();
        System.out.println("original pattern matches " + yes);
        String temp = pat.pattern();
        Pattern pat2 = Pattern.compile(temp);
        m = pat.matcher("5");
        yes = m.matches();
        System.out.println("second pattern matches " + yes);
    }
}


true
true
true
false
false
true
false
false
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Regular Expression

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App