Regular expression is a sequence of characters used for searching of pattern or matching of pattern.
e.g : Regex Pattern :- Java
Test String :- Java , C and Python all are programming languages.
Sample code in java :
import java.io.;
import java.util.Scanner;
import java.util.regex.;
class RegexSearch {
public void Pattern (String Regex_Pattern){
Scanner sc = new Scanner (System.in);
String Test_String = sc.nextLine();
Pattern p = Pattern.compile(Regex_Pattern);
Matcher m = p.matcher(Test_String);
System.out.println(m.find());
}
}
public class Main{
public static void main(String[] args){
RegexSearch obj = new RegexSearch();
obj.Pattern("Java");
}
Input: Java , C and python all are programming languages.
Output: true
You can view code here also.
Have a nice day , Coders.
Top comments (0)