regex class java code example
Example 1: java regex
import java.util.regex.*;
public class RegexExample1{
public static void main(String args[]){
Pattern p = Pattern.compile(".s");
Matcher m = p.matcher("as");
boolean b = m.matches();
boolean b2=Pattern.compile(".s").matcher("as").matches();
boolean b3 = Pattern.matches(".s", "as");
System.out.println(b+" "+b2+" "+b3);
}}
Example 2: regex java
import java.io.*;
import java.util.regex.*;
public class testRegex {
private static Pattern pattern;
private static Matcher matcher;
public static void main(String args[]) {
pattern = Pattern.compile("Hugo");
matcher = pattern.matcher("Hugo Etiévant");
while(matcher.find()) {
System.out.println("Trouvé !");
}
}
}