<< < 1 2 3   Sort: Date

Capturing query string from URL
How to capture query string from URL addresses with a regular expression? Here are URL address examples: ftp://ftp.example.org/ https://login.example.com:5800 /?mode=guest&lang=enhttp://www.google.com:80/api/e xample/submit.php?name=joe#newfile://localhost/c|/WINDOWS/do cument.html#chapter1URL a...
2013-02-03, 3052👍, 0💬

US Social Security Number validation
How to perform a validation on US Social Security Numbers using a regular expression? For example, " 333-23-2329 " is a valid US Social Security Number. To perform a basic validation on US Social Security Numbers, try this regular expression: ^[\d]{3}-[\d]{2}-[\d]{4}$
2013-01-27, 3036👍, 0💬

Finding blank lines in a text file
How to find blank lines in a text file using regular expression? You can use the following logic to find blank lines in a text file: 1. Read each line from the text file in a loop. 2. Validate each line with this regular expression: ^\s*$ 3. If matched, you know that this line is a blank line.
2013-01-29, 3011👍, 0💬

Parsing the "To:" field from emails
What would be the correct regex pattern to extract email addresses from a string coming from an email form "To" line, that allows the addresses to be delimited by commas ",", semicolons ";", or spaces? For example, the following "To" line contains 4 email addresses: "Joe Smith" , joe@aol.com; someon...
2013-01-30, 2997👍, 0💬

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, 2978👍, 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, 2970👍, 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, 2958👍, 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, 2933👍, 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, 2923👍, 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, 2914👍, 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, 2901👍, 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, 2888👍, 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, 2860👍, 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, 2849👍, 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, 2754👍, 0💬

Finding repeating words in a document
How to find repeating words in a text document with a regular expression? An example text document is listed below: After narrowly escaping a sensitive decapitation, Bond Bond is shot with a tranquilizer gun. He wakes up up on a plane to a woman standing over him, who introduces herself: "My name is...
2013-02-03, 2749👍, 0💬

<< < 1 2 3   Sort: Date