1import java.util.regex.*;
2public class RegexExample1{
3public static void main(String args[]){
4//1st way
5Pattern p = Pattern.compile(".s");//. represents single character
6Matcher m = p.matcher("as");
7boolean b = m.matches();
8
9//2nd way
10boolean b2=Pattern.compile(".s").matcher("as").matches();
11
12//3rd way
13boolean b3 = Pattern.matches(".s", "as");
14
15System.out.println(b+" "+b2+" "+b3);
16}}
1//Ther are three type of REGULAR EXPRESSION
2 //first
3 ^(.+)@(.+)$ "^(.+)@(.+)$\""
4 //second
5 ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$
6 //third
7 ^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?!-)(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
1import java.io.*;
2import java.util.regex.*;
3
4public class testRegex {
5
6 private static Pattern pattern;
7 private static Matcher matcher;
8
9 public static void main(String args[]) {
10 pattern = Pattern.compile("Hugo");
11 matcher = pattern.matcher("Hugo Etiévant");
12 while(matcher.find()) {
13 System.out.println("Trouvé !");
14 }
15 }
16}