Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Regular expression

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    Regular expression is basically a sequence of character.

    They are used for pattern matching.

    We can use these to match the string inside a string and can also replace the string by another.

     

    PHP have two kind of regular expression.

    1. POSIX regular expression.

    2. PERL style regular expression.

     

    POSIX regular expression

    In this various element are combined to form a complex regular expression.

    Simply matches one character with the other.

    Concept-

    1. [0-9]- It matches decimal of 0 to 9.

    2. [a-z]- It matches character of a to z of lower case.

    3. [A-Z]- It matches character of a to z of upper case.

    4. [a-Z]- It matches any character of a lower case to Z upper case.

    ex

    [^a-zA-Z]

     

    PERL style regular expression

    It is very similar to POSIX.

    The syntax can also be used for both.

    We can even use any quantifier.

    Meta character-

    It is simply an alphabetical character preceded by a backslash to give the combination of a special meaning.

    ex

    /([\d]+)000/

    here /d will search for any string of numerical character.

    .              a single character
    \s             a whitespace character (space, tab, newline)
    \S             non-whitespace character
    \d             a digit (0-9)
    \D             a non-digit
    \w             a word character (a-z, A-Z, 0-9, _)
    \W             a non-word character
    [aeiou]        matches a single character in the given set
    [^aeiou]       matches a single character outside the given set
    (foo|bar|baz)  matches any of the alternatives specified

     

     

     

 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: