Home Java Overview Maven Tutorials

Saturday 14 January 2017

Regular expression in java with example

For Video Tutorial : Move on Youtube Channel

Note : Select the playlist as per your need & move with number sequence

Regular expression in java with example

Regular expression (regex) is used in java to find a particular patter in an string.
Regular expression are used for defining staring patterns that can be used for searching, manipulating and editing a text.

Example : In below example we have used method Pattern.matches() to search a pattern in a string.

package javapkgn;
import java.util.regex.Pattern;
public class Creg
public static void main(String args[])
String abc = "hello how are you? hope you are fine";
String def = "(.)you(.)";
boolean isMatch = Pattern.matches(def, abc);
System.out.println("your matches are:" +isMatch);

your matches are:true
Note: This will search only single occurrence in text for pattern.

No comments:

Post a Comment