TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday, 13 April 2020

Java Regex | Java Regex Example | Java Regex In Hindi

Java Regex

The Java Regex or Regular Expression is an API to define a pattern for searching or manipulating strings.

It is widely used to define the constraint on strings such as password and email validation. After learning Java regex tutorial, you will be able to test your regular expressions by the Java Regex Tester Tool.Java Regex API provides 1 interface and 3 classes in java.util.regex package.

example of java regex

Fig: Java Regex

java.util.regex package


The Matcher and Pattern classes provide the facility of Java regular expression. The java.util.regex package provides following classes and interfaces for regular expressions.
1.    MatchResult interface
2.    Matcher class
3.    Pattern class
4.    PatternSyntaxException class

Example of java Regex

     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);   
      } }  

    

     Output:

             true  true  true

No comments:

Post a Comment