Regular Expression Interesting Usage Cases

1) misspelled words matching

Example:

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

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

Reference:

Character Classes or Character Sets

http://www.regular-expressions.info/charclass.html

2) calendar date matching

Example:

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

Reference:

Optional Items

http://www.regular-expressions.info/optional.html

3) HTML tag matching

Example:

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

Reference:

Laziness Instead of Greediness (lazy matching)

http://www.regular-expressions.info/repeat.html

Basics:

? 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 …

Advertisements

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:

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