Friday, 12 January 2018

How to use logical operators | Java Regex | Java Regular Expressions | Regex in java


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

RegexDemo1.java

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

/**
 *
 * Logical Operators
 *
 */

public class RegexDemo1
{

    public static void main(String[] args)
    {
        /*
         * The Logical Operator XY matches the X followed by Y.
         */

        Pattern pattern = Pattern.compile("to");
        Matcher matcher = pattern.matcher("Welcome to India");

        while (matcher.find())
        {
            System.out.println(matcher.group() + ", Match String start(): "
                    + matcher.start());
        }
    }

}

Output

to, Match String start(): 8

RegexDemo2.java

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

/**
 *
 * Logical Operators
 *
 */

public class RegexDemo2
{

    public static void main(String[] args)
    {
        /*
         * The Logical Operator X|Y matches the X or Y.
         */

        Pattern pattern = Pattern.compile("t|o");
        Matcher matcher = pattern.matcher("Welcome to India");

        while (matcher.find())
        {
            System.out.println(matcher.group() + ", Match String start(): "
                    + matcher.start());
        }
    }

}

Output

o, Match String start(): 4
t, Match String start(): 8
o, Match String start(): 9

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/7d1a1b8046fa2c6f340631d1f5b0f99be87e7675/BasicJava/RegexDemo_logical_operatior_to/?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
  • 1 comment:

    1. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
      Best Dot Net Training Institute in Chennai
      Best Software Testing Training Institute in Chennai With Placement
      Java Certification in Chennai
      PHP Training Institute in Chennai

      ReplyDelete