74 regular expressions found in this category!
Displaying page
of
pages;
Items to
Title |
Test
Details
Pattern Title
|
Expression |
^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$ |
Description |
Checks domain names. This validates domains based on latest specifications (RFCs 952 and 1123 dealing with hostnames and RFC 1035 dealing with domain name system requirements) except that it only includes realistic fully-qualified domains: 1. requires at least one subdomain 2. allows shortest top-level domains like "ca", and "museum" as longest.
Other validation rules: 1. Labels/parts should be seperated by period. 2. Each label/part has maximum of 63 characters. 3. First and last character of label must be alphanumeric, other characters alphanumeric or hyphen. 4. Does not check maxlength of domain which incidentally is 253 characters of text (255 binary representation).
For a regular expression that matches ALL domains:
^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$
|
Matches |
regexlib.com | this.is.a.museum | 3com.com |
Non-Matches |
notadomain-.com | helloworld.c | .oops.org |
Author |
Rating:
Remi Sabourin
|
Title |
Test
Details
Pattern Title
|
Expression |
^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}$ |
Description |
Regular expression for validating a decimal IP address. Matches 4 groups of from 1 to 3 digits, where each group of digits ranges from 0 to 255 in value. Groups of digits must be separated by a single period (.) with no other formatting characters present. Uses conditional regex with lookahead syntax to prevent a match on a period following the final group of digits. |
Matches |
217.6.9.89 | 0.0.0.0 | 255.255.255.255 |
Non-Matches |
256.0.0.0 | 0127.3 | 217.6.9.89. |
Author |
Rating:
Jerry Schmersahl
|
Title |
Test
Details
Pattern Title
|
Expression |
^((https?|ftp)\://((\[?(\d{1,3}\.){3}\d{1,3}\]?)|(([-a-zA-Z0-9]+\.)+[a-zA-Z]{2,4}))(\:\d+)?(/[-a-zA-Z0-9._?,'+&%$#=~\\]+)*/?)$ |
Description |
Using other regular experssions from this page, combining others for email addresses, and mixing in my own ideas - I came up with this regular expression. Can be used to validate input into a database. |
Matches |
http://207.68.172.254/home.ashx | ftp://ftp.netscape.com/ | https://www.brinkster.com/login.asp |
Non-Matches |
htp://mistake.com/ | http://www_address.com/ | ftp://www.files.com/file with spaces.txt |
Author |
Rating:
Benjamin Gray
|
Title |
Test
Details
Pattern Title
|
Expression |
^[^\\\/\?\*\"\'\>\<\:\|]*$ |
Description |
Validation of a Folder Name. Excludes all forbidden characters |
Matches |
321321321 dasds |
Non-Matches |
/\3fsdfsd |
Author |
Rating:
Nikolay Yordanov
|
Title |
Test
Details
Label all parts of a URL
|
Expression |
(?:(?<protocol>http(?:s?)|ftp)(?:\:\/\/))
(?:(?<usrpwd>\w+\:\w+)(?:\@))?
(?<domain>[^/\r\n\:]+)?
(?<port>\:\d+)?
(?<path>(?:\/.*)*\/)?
(?<filename>.*?\.(?<ext>\w{2,4}))?
(?<qrystr>\??(?:\w+\=[^\#]+)(?:\&?\w+\=\w+)*)*
(?<bkmrk>\#.*)? |
Description |
I needed a regular expression to break urls into labled parts. This is what I came up with. Got a few ideas from regexlib.com and from this msdn article. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/reconbackreferences.asp
http://www.domain.com/folder does return a match but will not grab the folder name unless there is "/" at the end.
http://www.domain.com/folder/ |
Matches |
https://192.168.0.2:80/users/~fname.lname/file.ext | ftp://user1: [email protected] | http://www.dom |
Non-Matches |
|
Author |
Rating:
Ariel Merrell
|
Title |
Test
Details
Pattern Title
|
Expression |
^([a-zA-Z]\:|\\\\[^\/\\:*?"<>|]+\\[^\/\\:*?"<>|]+)(\\[^\/\\:*?"<>|]+)+(\.[^\/\\:*?"<>|]+)$ |
Description |
This regular expression match any valid file path. It checks local drives and network path. The file extension is required. |
Matches |
c:\Test.txt | \\server\shared\Test.txt | \\server\shared\Test.t |
Non-Matches |
c:\Test | \\server\shared | \\server\shared\Test.? |
Author |
Rating:
Roberto Misticoni
|
Title |
Test
Details
Pattern Title
|
Expression |
^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$ |
Description |
RegExp for validating the format of IP Addresses. This works great with the ASP.NET RegularExpressionValidator server control. |
Matches |
127.0.0.1 | 255.255.255.0 | 192.168.0.1 |
Non-Matches |
1200.5.4.3 | abc.def.ghi.jkl | 255.foo.bar.1 |
Author |
Rating:
G. Andrew Duthie
|
Title |
Test
Details
Pattern Title
|
Expression |
^(((ht|f)tp(s?))\://)?((([a-zA-Z0-9_\-]{2,}\.)+[a-zA-Z]{2,})|((?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4}))(:[a-zA-Z0-9]+)?(/[a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~]*)?$ |
Description |
Hopefully an all-encompassing expression to validate a URL. Supports an optional protocol, either a domain or IP address, an optional port number and an optional path. |
Matches |
this.com | https://this.com:8080/this/this.htm | ftp://255.255.255.255/ |
Non-Matches |
.this.com | https://this.com:/ | ftps://255.256.255.255/ |
Author |
Rating:
Tom Hartland
|
Title |
Test
Details
All existing TLDs (Top-Level Domains) according to IANA specifications
|
Expression |
(a(?:[cdefgilmnoqrstuwxz]|ero|(?:rp|si)a)|b(?:[abdefghijmnorstvwyz]iz)|c(?:[acdfghiklmnoruvxyz]|at|o(?:m|op))|d[ejkmoz]|e(?:[ceghrstu]|du)|f[ijkmor]|g(?:[abdefghilmnpqrstuwy]|ov)|h[kmnrtu]|i(?:[delmnoqrst]|n(?:fo|t))|j(?:[emop]|obs)|k[eghimnprwyz]|l[abcikrstuvy]|m(?:[acdeghklmnopqrstuvwxyz]|il|obi|useum)|n(?:[acefgilopruz]|ame|et)|o(?:m|rg)|p(?:[aefghklmnrstwy]|ro)|qa|r[eosuw]|s[abcdeghijklmnortuvyz]|t(?:[cdfghjklmnoprtvwz]|(?:rav)?el)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]) |
Description |
This regexp matches all existing TLDs (Top-Level Domains) according to IANA specifications as of 14/07/2007. |
Matches |
all ccTLDs (Country-Code Top-Level Domains) | all gTLDs (Generic Top-Level Domains) | .arpa |
Non-Matches |
n.o.n - e.x.i.s.t.i.n.g T.L.D.s |
Author |
Rating:
Daniel Beck
|
Title |
Test
Details
Pattern Title
|
Expression |
^(ht|f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$ |
Description |
Cheap and cheerful URL checker. Requires a http/https/ftp at the start and will then allow anything starting with at least a <something>.<something>.<something> then valid characters separated by dots and slashes |
Matches |
http://www.thedaddy.org | http://forum.thedaddy.org/index.html | ftp://hows.it.going_buddy/checkit/o |
Non-Matches |
www.thedaddy.org | http://hello | ftp://check.it |
Author |
Rating:
John Main
|
Title |
Test
Details
Pattern Title
|
Expression |
^([a-zA-Z]\:) (\\{1}| ((\\{1}) [^\\] ([^/:*?<>"|]*(?<![ ])))+)$ |
Description |
Validates windows path and invalidates UNC path |
Matches |
c:\34\445\546\3.htm | C:\ |
Non-Matches |
\\qaz | c:\Ram<\ | C: or c:\\ or \\ |
Author |
Rating:
Gaurav Shrivastava
|
Title |
Test
Details
Pattern Title
|
Expression |
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+\.(txt|TXT)$ |
Description |
It matches .jpg files. It allows for a dot in the path. A dot may occur in such directories as: C:\Documents and Settings\roman.lukyanenko\Desktop\stuff\b_card2.txt or C:\Windows\Microsoft.NET etc |
Matches |
C:\Documents and Settings\roman.lukyanenko\Desktop\stuff\b_card2.txt |
Non-Matches |
C:\file.doc |
Author |
Rating:
Roman Lukyanenko
|
Title |
Test
Details
Pattern Title
|
Expression |
^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$ |
Description |
Version 1.3.0: I needed a regexp to validate URL's without the ht(f)tp(s):// and include North American domains (like .us and .ca) and there didn't seem to be one available...so I created one. It will also work with ASP QueryStrings and anchor URL's. If you have a problem with the expression or have any suggestions to improve, please write me and let me know. Added .uk domain and expression now allows for URLs that contain JSP session IDs. 4/14/04 - added ability to include URLs that start with server names. |
Matches |
www.blah.com:8103 | www.blah.com/blah.asp?sort=ASC | www.blah.com/blah.htm#blah |
Non-Matches |
www.state.ga | http://www.blah.ru |
Author |
Rating:
Brad Dobyns
|
Title |
Test
Details
Pattern Title
|
Expression |
^(\$)?(([1-9]\d{0,2}(\,\d{3})*)|([1-9]\d*)|(0))(\.\d{2})?$ |
Description |
Modified Joe Lynwood's to allow zero amounts. Handles US Dollars including zero dollars. |
Matches |
$1,234,567.89 | 1234567.89 | $0.00 |
Non-Matches |
$1,2345,67.89 | $1234,345,678.0 |
Author |
Rating:
Jason Roe
|
Title |
Test
Details
Pattern Title
|
Expression |
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])? |
Description |
*CORRECTED: Again thanks for all the comments below. If you want to include internal domain as well change the partial code (\.[\w-_]+)+ to (\.[\w-_]+)?
See the comments below*
This is the regular expression I use to add links in my email program. It also ignores those suppose-to-be commas/periods/colons at the end of the URL, like this sentence "check out http://www.yahoo.com/." (the period will be ignored) Note that it requires some modification to match ones that dont start with http. |
Matches |
http://regxlib.com/Default.aspx | http://electronics.cnet.com/electronics/0-6342366-8-8994967-1.html |
Non-Matches |
www.yahoo.com |
Author |
Rating:
M H
|
Title |
Test
Details
Pattern Title
|
Expression |
(\s|\n|^)(\w+://[^\s\n]+) |
Description |
will match free floating valid protocol + urls in text ... will not touch the ones wrapped in a tag, so that you can auto-link the ones that aren't :) couple of things to know :
1. if the url is next to a tag this won't work (eg : <br>http://www.acme.com), the url must either start with a \s, \n or any character other than >.
2. the pattern will match the preceding \s and \n too, so when you replace put them back in place $1 will either be \s or \n, $2 will be the exact match
vb usage :
set re = New RegExp
re.Pattern ="(\s|\n|^)(\w+://[^\s\n]+)"
strResult = re.Replace(strText, "$1<a href='$2' target='_new'>$2</a>") |
Matches |
http://www.acme.com | ftp://ftp.acme.com/hede | gopher://asdfasd.asdfasdf |
Non-Matches |
<a href="http://acme.com">http://www.acme.com</a> | <br>http://www.acme. |
Author |
Rating:
ic onur
|
Title |
Test
Details
Pattern Title
|
Expression |
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+\.(jpg|JPG)$ |
Description |
It matches .jpg files. It allows for a dot in the path. A dot may occur in such directories as: C:\Documents and Settings\roman.lukyanenko\Desktop\stuff\b_card2.jpg
or C:\Windows\Microsoft.NET etc |
Matches |
C:\Documents and Settings\roman.lukyanenko\Desktop\stuff\b_card2.jpg | C:\b_card.jpg | \\network\fol |
Non-Matches |
C:\file.xls |
Author |
Rating:
Roman Lukyanenko
|
Title |
Test
Details
Pattern Title
|
Expression |
\b([\d\w\.\/\+\-\?\:]*)((ht|f)tp(s|)\:\/\/|[\d\d\d|\d\d]\.[\d\d\d|\d\d]\.|www\.|\.tv|\.ac|\.com|\.edu|\.gov|\.int|\.mil|\.net|\.org|\.biz|\.info|\.name|\.pro|\.museum|\.co)([\d\w\.\/\%\+\-\=\&\?\:\\\"\'\,\|\~\;]*)\b |
Description |
Url matching |
Matches |
http://210.50.2.215/sd_new/WebBuilder.cgi?RegID=7449046&First=Ok&Upt=Ok&EditPage=3&S |
Non-Matches |
Hmmmm |
Author |
Rating:
Johky Cheng
|
Title |
Test
Details
Pattern Title
|
Expression |
\A([A-Za-z0-9'~`!@#$%&^_+=\(\){},\-\[\]\;])+?([ A-Za-z0-9'~`
!@#$%&^_+=\(\){},\-\[\];]|([.]))*?(?(3)(([ A-Za-z0-9'~`!@#$
%&^_+=\(\){},\-\[\]\;]*?)([A-Za-z0-9'~`!@#$%&^_+=\(\){},\-\[
\];])+\z)|(\z)) |
Description |
Used to match windows filenames. Fails if there is leading or trailing spaces. Fails if the input contains /\:*?"<>| . Fails if the input begins or ends with '.' |
Matches |
Test.txt | T est.txt | Rosco's.Test.txt |
Non-Matches |
\Folder\Test.txt | T*est.txt | Test. |
Author |
Rating:
Rosco Pikotrain
|
Displaying page
of
pages;
Items to