Tuesday 2 January 2018

How to use Quantifiers a{3} | Java Regex | Java Regular Expressions | Regex in java


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=Ci8uKc_C3V4&list=UUhwKlOVR041tngjerWxVccw

RegexDemo.java

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * Quantifiers
 *
 */

public class RegexDemo
{

    public static void main(String[] args)
    {
        isMatch("a{3}", "aaa");
        isMatch("a{3}", "aa");
        isMatch("a{3}", "aaaaaa");
    }

    private static void isMatch(String regex, String inputText)
    {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(inputText);

        System.out.println("Regex = " + regex + " , " + "InputText = "
                + inputText + " is matching? = " + matcher.matches());
    }

}

Output

Regex = a{3} , InputText = aaa is matching? = true
Regex = a{3} , InputText = aa is matching? = false
Regex = a{3} , InputText = aaaaaa is matching? = false

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/RegexDemo_quantifers_a_3times.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/RegexDemo_quantifers_a_3times

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/9ca0aed85cf523c7d53f60f93dd6c7d098a3db63/BasicJava/RegexDemo_quantifers_a_3times/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment