Wednesday, 1 August 2012

You Don’t Know Anything About Regular Expressions: A Complete Guide



Regular expressions can be scary…really scary. Fortunately, once you memorize what each symbol represents, the fear quickly subsides. If you fit the title of this article, there’s much to learn! Let’s get started.

Section 1: Learning the Basics


The key to learning how to effectively use regular expressions is to just take a day and memorize all of the symbols. This is the best advice I can possibly offer. Sit down, create some flash cards, and just memorize them! Here are the most common:



. – Matches any character, except for line breaks if dotall is false.


* – Matches 0 or more of the preceding character.


+ – Matches 1 or more of the preceding character.


? – Preceding character is optional. Matches 0 or 1 occurrence.


\d – Matches any single digit


\w – Matches any word character (alphanumeric & underscore).


[XYZ] – Matches any single character from the character class.


[XYZ]+ – Matches one or more of any of the characters in the set.


$ – Matches the end of the string.


^ – Matches the beginning of a string.


[^a-z] – When inside of a character class, the ^ means NOT; in this case, match anything that is NOT a lowercase letter.

There are many tools available in market with the help of which you can automatically create regular expressions and of course not forcing you to scratch your head. I have mentioned some of the common tools that i have used.




RegExr Desktop app is essential, and is really quite fun to fool around with. In addition to real-time checking, it also offers a sidebar which details the definition and usage of every symbol. Download it!.

No comments:

Post a Comment