• +91 9723535972
  • info@interviewmaterial.com

Regular Expressions Interview Questions and Answers

Question -
What is an example of Java Regular Expressions?



Answer -

Here is an example of Java Regular Expression:
import java.util.regex.*;  
public class RegexExample1{  
public static void main(String args[]){  
//1st way  
Pattern p = Pattern.compile(".s");//. represents single character  
Matcher m = p.matcher("as");  
boolean b = m.matches();  
 
//2nd way  
boolean b2=Pattern.compile(".s").matcher("as").matches();  
 
//3rd way  
boolean b3 = Pattern.matches(".s", "as");  
 
System.out.println(b+" "+b2+" "+b3);  
}}  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners