I am trying to generate a regular expression match in Java, that accepts all numbers that contain 3 and 7 (in any order, ie there should be at least one 7 for all 3’s and vice versa) over the set of integers. So far, I have written the code below, however I am not able to get the correct output. Any kind of help will be appreciated:
class Main {
public static void main (String[] args) throws java.lang.Exception {
System.out.println("333333".matches("[[3][7]+]*") ? "Yes" : "No");
}
}
Here, I should be getting the output as NO, since the given string is only of 3’s not of 3 and at least one 7.
I’m not sure if a regex is necessary. Why not use the following: