Regex

From NoskeWiki
Jump to: navigation, search

About

Regular Expression ("REGEX" for short) is a VERY powerful tool for matching string patterns(typically for find and replace) using advanced wildcard options. I'd highly recommend visiting the links (below) to learn more - can save you LOTS of code if you want to do advanced find & replace text operations.

Below is a summary of the most useful and common regex meta characters and special characters:

Regex special chars.gif

Regex metachars.gif


Examples

\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b     -> to match ANY e-mail address
\d{2}-\d{5}                                   -> finds ID # in format: 2 digits, hyphen, 5 digits


^\s*$               -> maches a blank line.
"[\t ]+\n", "\n"    -> removes trailing whitespaces from sentences.


Interactive Regex Webpages


Links