<< < 1 2 3 4 5 6 >   Sort: Date

Parsing header lines of an email message
How write a regular expression to capture all header lines from an email message like this: Return-Path: X-Original-To: test@example.com Delivered-To: test@example.com Message-ID: Date: Thu, 23 Jun 2011 11:26:29 +0200 From: Example Sender To: Example Receiver Subject: Email example Hello Joe, It was...
2013-02-01, 2966👍, 0💬

Validating United Kingdom postcodes
How to write a regular expression to validate United Kingdom postcodes? For example, EC1A 1BB is a valid UK postcodes. Here is the regular expression to validate United Kingdom postcodes: [A-Z]{1,2}\d[A-Z\d]? \d[ABD-HJLNP-UW-Z]{2} [A-Z]{1,2} - 1 or 2 letters \d - A digit [A-Z\d]? - An optional lette...
2013-01-29, 2960👍, 0💬

IP address validation
How to perform a validation on IP addresses using a regular expression? For example, " 198.168.1.78 " is an valid IP address. To perform a validation on IP addresses, try this regular expression: ^(([1-9]?\d|1\d{2}|2[0-4]\d|25 [0-5]).){3}([1-9]?\d|1\d{2}|2[ 0-4]\d|25[0-5])$
2013-01-27, 2953👍, 0💬

Logical OR (Alternation) operation (a|b)
What is a logical OR operation? How to specify a logical OR operation in a regular expression? How to use logical OR operations to build a regular expression to search and count common spamming terms from this email paragraph: I am inviting you for a business deal where this money will be shared bet...
2013-01-22, 2926👍, 0💬

Capturing domain name from URL
How to capture scheme name from URL addresses with a regular expression? Here are URL address examples: ftp://ftp.example.org https://login.example.com:5800 /http://en.wikipedia.org/wiki/W WW.html#Historyfile://localhost/c|/WINDOWS/cl ock.aviURL addresses are written in this format: scheme://domain:...
2013-02-03, 2916👍, 0💬

Finding content between two quotes
How to find content between two quotes in a text string using regular expression? For example, I have the following string: print "\$45.00\n"; Here is the regular expression to capture the content between two quotes: "([^"]*)"
2013-01-29, 2913👍, 0💬

0 or more times repetition quantifier *
What is the 0 or more times repetition quantifier? How to use it? How to write a regular expression using a repetition quantifier to capture all names and values in a URL query string like this: User=Jack&Age=&City=Pa ris? The "0 or more times" repetition quantifier allows us to repeat a pat...
2013-01-26, 2905👍, 0💬

Capturing attributes of XML elements
How to capture attributes of XML elements in XML documents? An example XML document is listed below: The regular expression to capture attributes of XML elements in an XML document can be written as: ([^\s=]+)\s*=\s*"((?:[^"]*\")* [^"]*)"Note that: ([^\s=]+) - Attribute name ((?:[^"]*\")*[^"]*) - At...
2013-02-02, 2902👍, 0💬

Capturing authenticated user name from Apache Web log file
How to capture the authenticated user name from Apache Web log file? Here are some Apache Web log file entries: 127.0.0.1 - frank [10/May/2012:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "-" "-" "-" 213.135.131.79 - - [15/May/2012:19:21:49 -0400] "GET /features.htm HTTP/1.1" 200 9955 "htt...
2013-02-03, 2890👍, 0💬

Finding mismatching quotes in a code line
How to find mismatching quotes "..." in a program code line with a regular expression? The the example program code is listed below: error = "Line "+line+" position "+position+" has invalid character "+char; warning = "The quote character (") may cause problem at line "+line+" position "+position; T...
2013-02-02, 2882👍, 0💬

End of string anchor $
What is the "end of string" anchor in a regular expression? How to use it? How to write a regular expression using "end of string" anchor to validate words ending in 'z': quartz ? The "end of string" anchor is an atomic zero-width assertion specifing that the match must occur at the end of the strin...
2013-01-26, 2876👍, 0💬

Possessive (non-backtracking) quantified subpatterns ++ *+ {}+
What is possessive (non-backtracking) quantified subpatterns? How to write a possessive quantified subpattern to match double-quoted strings like this: "He said: \“Hello!\”" ? If you don't want the default backtracking behavior of quantified subpatterns, you can turn it off by adding the "poss...
2013-01-26, 2864👍, 0💬

Capturing host name from Apache Web log file
How to capture the remote host name from Apache Web log file? Here are some Apache Web log file entries: 127.0.0.1 - frank [10/May/2012:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "-" "-" "-" 213.135.131.79 - - [15/May/2012:19:21:49 -0400] "GET /features.htm HTTP/1.1" 200 9955 "http://www...
2013-02-03, 2853👍, 0💬

Validating Canadian Postal Codes
How to write a regular expression to validate Canadian Postal Codes? For example, T2X 1V4 is a valid Canadian postal codes. Here is the regular expression to validate Canadian postal codes: [ABCEGHJKLMNPRSTVXY]\d[A-Z] ?\d[A-Z]\d [ABCEGHJKLMNPRSTVXY] - 18 FSA possible letters \d - A digit [A-Z] - Any...
2013-01-29, 2836👍, 0💬

n or more times repetition quantifier {n,}
What is the "n or more times" repetition quantifier? How to use it? How to write a regular expression using a repetition quantifier to capture the value of PI like: 3.1415926535897932384626433832 795028841971with a precision of at least 5 decimal digits? The "n or more times" repetition quantifier a...
2013-01-26, 2836👍, 0💬

Pattern groups (...)
What is pattern group? What are pattern groups used for? How to write a regular expression using groups to capture character names from the Ed, Edd 'n' Eddy animated comedy television series? The grouping mechanism allows a part of a regex to be treated as a single unit. A group is represented by re...
2013-01-23, 2809👍, 0💬

Exact n times repetition quantifier {n}
What is the exact n times repetition quantifier? How to use it? How to write a regular expression using a repetition quantifier to capture Visa card numbers that have 16 digits like this: 4111111111111111 ? The "exact n times" repetition quantifier allows us to repeat a pattern unit exactly n times ...
2013-01-26, 2788👍, 0💬

1 or more times repetition quantifier +
What is the 1 or more times repetition quantifier? How to use it? How to write a regular expression using a repetition quantifier to capture all words in a PHP script code like this: function get($key) {if (array_key_exists($key,$_POST) )return $_POST[$key]; else return "";} ? --- Answer The "1 or m...
2013-01-26, 2766👍, 0💬

Greediness of quantified subpatterns
What is the greediness of quantified subpatterns? What does it mean that a quantified subpattern is "greedy"? How to show that a quantified subpattern is "greedy" on this PHP script: if ($t=10): echo "Just started...!"; endif; if ($t=11): echo "Hungry!"; endif; if ($t=12): echo ""Ah, lunch-time!"; e...
2013-01-26, 2766👍, 0💬

Limited number of repetitions quantifier {n,m}
What is the limited number of repetitions quantifier? How to use it? How to write a regular expression using a repetition quantifier to ensure my password is between 8 and 12 characters long like this one: 9EA979114C ? The "limited number of repetitions" quantifier allows us to repeat a pattern unit...
2013-01-26, 2765👍, 0💬

Start of string anchor ^
What is the "start of string" anchor in a regular expression? How to use it? How to write a regular expression using "start of string" anchor to validate discover credit card numbers like: 6011963280099774 ? The "start of string" anchor is an atomic zero-width assertion specifing that the match must...
2013-01-26, 2746👍, 0💬

1 or 0 times repetition quantifier ?
What is the 1 or 0 times repetition quantifier? How to use it? How to write a regular expression using a 1 or 0 times repetition quantifier to capture both spellings of skilful and skillful ? The "1 or 0 times" repetition quantifier allows us to create a special logical OR operation of "match the pa...
2013-01-26, 2739👍, 0💬

Capturing port number from URL
How to capture port number from URL addresses with a regular expression? Here are URL address examples: ftp://ftp.example.org https://login.example.com:5800 /http://en.wikipedia.org:80/wik i/WWW.html#Historyfile://localhost/c|/WINDOWS/cl ock.aviURL addresses are written in this format: scheme://doma...
2013-02-03, 2738👍, 0💬

Backtracking of quantified subpatterns
What is backtracking of quantified subpatterns? What does it mean that a quantified subpattern is "backtracked"? How to show that a quantified subpattern is "backtracked" on this PHP script: if ($t=10): echo "Just started...!"; endif; if ($t=11): echo "Hungry!"; endif; if ($t=12): echo ""Ah, lunch-t...
2013-01-26, 2730👍, 0💬

<< < 1 2 3 4 5 6 >   Sort: Date