Friday, 22 December 2017

How to check http:// contains in the input text | Java Regex | Regex in java

RegexDemo.java

import java.util.regex.Pattern;

public class RegexDemo
{

    public static void main(String[] args)
    {
        /*
         * The inputText variable contains the text to be checked with
         * the regular expression.
         */

        String inputText = "This is the text to be searched "
                + "for occurrences of the http:// pattern.";

        /*
         * The regular expression matches all texts which contains one
         * or more characters (.*) followed by the text http://
         * followed by one or more characters (.*).
         */

        String regex = ".*http://.*";

        /*
         * the Pattern.matches() static method to check if the regular
         * expression (pattern) matches the text. If the regular
         * expression matches the text, then Pattern.matches() returns
         * true. If the regular expression does not match the text
         * Pattern.matches() returns false.
         */

        boolean matches = Pattern.matches(regex, inputText);

        System.out.println("matches = " + matches);

    }

}

Output

matches = true

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

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

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