Regular Expression Interesting Usage Cases

1) misspelled words matching


sep[ae]r[ae]te to match “seperate”, “separete”, “seperete”, “separate”

li[cs]en[cs]e to match “license”, “lisense”, “licence”, “lisence”


Character Classes or Character Sets

2) calendar date matching


Feb(ruray)? 23(rd)? to match February 23rd, February 23, Feb 23rd and Feb 23


Optional Items

3) HTML tag matching


<.+?> to match “<EM>” in “<EM>first</EM>” (lazy plus)


Laziness Instead of Greediness (lazy matching)


? to match zero or one time

* to match zero or more times

+ to match one or more times

. to match any single character but line break

\n to match new line

\b to mach word boundary

+? to match the previous element one or more times, but as few times as possible

?= positive lookahead

To be continue …


About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application and tagged . Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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