Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Regex for website.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 400
    Comment on it

                       Regular expressions(abbreviated regex or regexp) are the sequence of characters to match different set of patterns ,strings or inputs . The concept was developed by American Mathematician Stephen Kleene as regular language. The regex is used to identify textual material of given pattern, or process a number of instances that are closest to the patterns. A word with two different forms can be identified using regex ex:- the regular expression seriali[sz]e matches both "serialise" and "serialize".

                      As in our real life there are lots of name and words which follows a pattern Like email, website, Mobile number etc. So to check whether an expression is matching the certified pattern or not, we make regex or regular expression. Below is given an example of regex for webite and following matches.

    (Reg-ex for website)

    /((https?:\/\/)|(https?:\/\/)?[w]{3}\.){1}([a-z-A-Z0-9]+)(([.][a-zA-Z]{3,9}){1}([.][a-zA-Z]{2})?|(([.][a-zA-Z]{2}){2}))/;

    It contains the reg-ex for all the matching patterns.

    Example :

    1. www.abc.com    || https://abc.com     || http://abc.com      
    || https://www.abc.com
    2. www.abc.co.in  || https://abc.co.in   || http://abc.co.in    
    || https://www.abc.co.in
    3. www.abc.gov.in || https://abc.gov.in  || http://abc.gov.in   
    || https://www.abc.gov.in
    4. www.abc.coupon || https://abc.coupon  || http://abc.coupon   
    || https://www.abc.coupon
    5. www.a.coupon.in|| https://a.coupon.in || http://a.coupon.in  
    || https://www.a.coupon.in
    
    

    Any other expression not matching the above one will provide a mismatch.
    Example :

    1. www.abc           ||  https://abc          ||  https://abc          
    ||  https://abc
    2. www.abc.          ||  https://abc.         ||  https://abc.         
    ||  https://abc.
    3. www.abc.com.com   ||  https://abc.com.com  ||  https://abc.com.com  
    ||  https://abc.com.com
    4. www.abc.co.co.in  ||  https://abc.co.ci.in ||  https://abc.co.ci.in 
    ||  https://abc.co.ci.in
    5. www.abc.co.com    ||  https://co.com       ||  https://co.com       
    ||  https://co.com 
    
    

    Symbols and there meanings :

    1. ^ to make pattern mandatory.
    2. ? stands for zero or one occurrence of pattern.
    3. \ used as meta-character to give special meaning to some patterns (\/ is used for /(as it can not be used directly)).
    4. [a-z A-Z] all the alphabets between A to Z and a to z.
    5. [0-9] all digits from 0 to 9.
    6. + one or more occurrences.
    7. * zero or more occurrences.
    8. [.] an occurrence of ".".
    9. {} defines the pattern ( ([a-z]{2}) only two alphabets between a to z).
    10. | Or Symbol for making different patterns.
    11. $ end of Expression.

    Reference link:

    http://en.wikipedia.org/wiki/Regular_expression
    http://www.regular-expressions.info/tutorial.html
    http://www.w3schools.com/jsref/jsref_obj_regexp.asp

    check your regex online:

    http://www.regexr.com
    http://regex101.com

 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: