Tuesday, 19 December 2017

How to use find method of matcher class | Java Regex | Java Regular Expressions | Regex in java


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

RegexDemo.java

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

public class RegexDemo
{
    public static void main(String[] args)
    {
        String input = "TV Price is 500 Rs";
        String regex = "(.*)(\\d+)(.*)";

        /*
         * Parameters:
         *
         * regex - The expression to be compiled
         *
         * Returns:
         *
         * the given regular expression compiled into a pattern
         *
         */

        Pattern patternObj = Pattern.compile(regex);

        /*
         * Parameters:
         *
         * input - The character sequence to be matched
         *
          * Returns:
         *
         * A new matcher for this pattern
         */

        Matcher matcher = patternObj.matcher(input);
        /*
         * Returns:
         *
         * true if, and only if, a subsequence of the input sequence
         * matches this matcher's pattern
         */

        System.out.println(matcher.find());
    }

}

Output

true

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/ef02c9011c18b0aa670526ba89cc11f493b9b854/BasicJava/RegexDemo_matcher_find/?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