How do I find a match of multiple digit number from a larger digit input using regex?

Viewed 20

I am using regex for the first time and I want to change the values in the curly brackets in "Match 1" and "Match 2" so that they return their boolean values as true.

From my understanding, the code in both print statements should return "true" because "789" are found in the inputs 0 times. Am I misunderstanding the use of the brackets and curly braces? What should I change the 0 to in order to return a true value?

import java.util.regex.Pattern;

public class PA2 {
    public static void main (String[] args){
        System.out.println("Match 1: " + Pattern.matches("[789][0-9]{0}", "99530"));
        System.out.println("Match 2: " + Pattern.matches("[789]{0}[0-5]{0}", "89530"));
    

    }
    
}```
0 Answers
Related