Regular Expressions Notes

  • – Matches any character except \n

  •  ^ – start

  •  $ – end

  •  \b – word Boundary

    •  
      • eg: \bBT\w*\b will select words starting with BT. 
      • eg: hai “mahesh” how is “raj”
        regex: \”.*\” will match “mahesh” how is “raj” — becoz * is greedy
        regex: \”[^”]\” will match “mahesh” and “raj”  — here we are negating ” in between double quotes i.e., we dont want double quote in between double quotes
  • | – alternation

    • \b(cat|dog)\b — select a word which is either cat or dog
    •  Get|GetValue on string “GetValue” results in selecting as GetValue since Regex Engine is eager
    • Once Get in the regex is matched with the String .. engine stops proceeding and reports success Matching Get
       solution: GetValue|Get     or   Get(Value)?
  • ? – Optional Items

    • Feb(ruary)? 23(rd)? matches February 23rd, February 23, Feb 23rd and Feb 23
    • colou?r matches colour, color

 i.e., preceding token is optional. Regex Engine continues searching even if match of preceeding token failes

Advertisements

About Uma Mahesh

A Creator/Equilizer. Creator/Equalizers are catalysts for positive, well-organized change. They never settle for the status quo. Instead, they see the opportunity for innovation in the processes that others have long taken for granted. They respect what's already operating, but they can't help but want to improve upon it. Their special combination provides innovation tempered with profound logic. They have incredible discernment. Should their efforts fail, they are unhesitating in accepting responsibility. They don't wallow in self-pity but rather see these missed attempts as critical steps on the path to success.
This entry was posted in Articles, Notes, Tutorials and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s