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 wikihead

A security freak
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s