Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is regular expression?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 303
    Comment on it

    Regular expression or Regex is an API which is used for pattern matching and it basically defines a search pattern of input.  We can also search, edit or manipulate text or data from regular expression. Let’s suppose if we need to define some constraints on any string(eg: passwords and email validation) then we will use regular-expression.

    Benefit of regex:

    1> Regex are fast for execution

    2> Regex save time

    3> Regex can match just about anything

    4> Searching (and possibly replacing) text in files

    Eg: Search pattern: (text)

            Replace: $text

    The search pattern text will replace from replaced text in a file.

     

    5> Renaming a hundred files at a time

    Eg: Changing the File Extension:

           Search pattern: ^(.*\.)[^.]+$

           Replace: $1rar

    ^(.*\.)[^.]--> Matches any character after the dot and then replace that string that is extension with rar.

     

    Java Regex API provides 1 interface and 3 classes in java.util.regex package.

     

    1. MatchResult interface

    2. Matcher class

    3. Pattern class

    4. PatternSyntaxException class

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: