Handige regular expressions

From Wowww mediawiki

Jump to: navigation, search

Vind de laatste occurrence van een string

Term : Negative lookahead


E-mail validation

According to official standard RFC 2822 http://stackoverflow.com/questions/201323/how-to-use-a-regular-expression-to-validate-an-email-addresses/4554294#4554294


Special Characters
There are 11 characters with special meanings: the opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). These special characters are often called "metacharacters".

Non-printable Characters
You can use special character sequences to put non-printable characters in your regular expression. Use \t to match a tab character (ASCII 0x09), \r for carriage return (0x0D) and \n for line feed (0x0A). More exotic non-printables are \a (bell, 0x07), \e (escape, 0x1B), \f (form feed, 0x0C) and \v (vertical tab, 0x0B). Remember that Windows text files use \r\n to terminate lines, while UNIX text files use \n.

You can use a hyphen inside a character class to specify a range of characters. [0-9] matches a single digit between 0 and 9. You can use more than one range. [0-9a-fA-F] matches a single hexadecimal digit, case insensitively.
The dot matches a single character, without caring what that character is.

Some examples for quick help :
Check on valid email address : \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
Find a word, even if it is misspelled, such as sep[ae]r[ae]te or li[cs]en[cs]e.
Find an identifier in a programming language with [A-Za-z_][A-Za-z_0-9]*.

Personal tools