74 regular expressions found in this category!
Displaying page
of
pages;
Items to
| 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 |
^(\$)?(([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 |
^([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 |
^\\{2}[\w-]+\\(([\w-][\w-\s]*[\w-]+[$$]?$)|([\w-][$$]?$)) |
| Description |
Validates a UNC to conform to \\server\service
Must have a "\\" at the start
Server may contain alpha/numeric/underscore/dash,
Followed by another single "\"
Service may contain alpha/numeric/underscore/dash/$/space
Note:
Service may not start nor end with a space
Service may only contain one $, and only at the end
No additional "\" may follow afterwards
|
| Matches |
\\server\service | \\server\my service | \\serv_001\service$ |
| Non-Matches |
\\my server\service | \\server\ service | \\server$\service |
| Author |
Rating:
Paul Haines
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^([a-zA-Z].*|[1-9].*)\.(((j|J)(p|P)(g|G))|((g|G)(i|I)(f|F)))$ |
| Description |
Regular expression to limit types of files accepted. This example matches .jpg and .gif files only. |
| Matches |
filename.jpg | FileName.JPG | filename.gif |
| Non-Matches |
filename.png | filename.xxx | filename.bmp |
| Author |
Rating:
Ramon Hildreth
|
| 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 |
^[^\\\/\?\*\"\'\>\<\:\|]*$ |
| Description |
Validation of a Folder Name. Excludes all forbidden characters |
| Matches |
321321321 dasds |
| Non-Matches |
/\3fsdfsd |
| Author |
Rating:
Nikolay Yordanov
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^(?=[^&])(?:(?<scheme>[^:/?#]+):)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))? |
| Description |
Use it for breaking-down a URI (URL, URN) reference into its main components: Scheme, Authority, Path, Query and Fragment.
This is not a simple match regular expression. so it not works to verify a URI. It returns 1 matching group for each URI component.
For example, for the following URI:
http://regexlib.com/REDetails.aspx?regexp_id=x#Details
returns: scheme="http", authority="regexlib.com", path="/REDetails.aspx", query="regexp_id=x" and fragment="Details".
This is a W3C raccomandation (RFC 2396). |
| Matches |
http://regexlib.com/REDetails.aspx?regexp_id=x#Details |
| Non-Matches |
& |
| Author |
Rating:
Frederico Knabben
|
| Title |
Test
Details
Pattern Title
|
| Expression |
(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)? |
| Description |
You can use this regular expression in your PHP scripts to convert entered URL in text to URL link. Example:
$text=ereg_replace("(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?","<a href=\"./redir.php?url=\\0\" target=\"_blank\">\\0</a>",$text); |
| Matches |
http://diskusneforum.sk | www.diskusneforum.sk | ftp://123.123.123.123/ |
| Non-Matches |
diskusneforum.sk |
| Author |
Rating:
Martin Ille
|
| 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:pwd@www.domain.com | http://www.dom |
| Non-Matches |
www.domain.com | user1:pwd@domain.com | 192.168.0.2/folder/file.ext |
| Author |
Rating:
Ariel Merrell
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$ |
| Description |
Modified URL RegExp that requires (http, https, ftp)://, A nice domain, and a decent file/folder string. Allows : after domain name, and these characters in the file/folder sring (letter, numbers, - . _ ? , ' / \ + & % $ # = ~). Blocks all other special characters-good for protecting against user input! |
| Matches |
http://www.blah.com/~joe | ftp://ftp.blah.co.uk:2828/blah%20blah.gif | https://blah.gov/blah-blah.as |
| Non-Matches |
www.blah.com | http://www.blah"blah.com/I have spaces! | ftp://blah_underscore/[nope] |
| Author |
Rating:
Brandon Luhring
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![ ]))*(\.[a-zA-Z]{2,6})$ |
| Description |
Matches filenames.
UPDATED on 1st Jan 2004. |
| Matches |
C:\di___r\fi_sysle.txt | c:\dir\filename.txt |
| Non-Matches |
c:\dir\file?name.txt |
| Author |
Rating:
Darren Neimke
|
| 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 |
^(ht|f)tp((?<=http)s)?://((?<=http://)www|(?<=https://)www|(?<=ftp://)ftp)\.(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(co|me|org|ltd|plc|net|sch|ac|mod|nhs|police|gov)\.uk$ |
| Description |
UK domains with protocol for http/https/ftp. Based on my previous expression, this allows the subdomain "www" for the http/https protocols, or "ftp" for the ftp protocol only. |
| Matches |
http://www.zeropanic.co.uk | ftp://ftp.sunsite.ac.uk | https://www.z2.co.uk |
| Non-Matches |
gopher://www.z2.co.uk | http://ftp.z2.co.uk | ftp://www.z2.co.uk |
| Author |
Rating:
Amos Hurd
|
| Title |
Test
Details
Pattern Title
|
| Expression |
([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?<!&|=)(?!\.\s|\.{3}).*?))(\s|$) |
| Description |
This will find URLs in plain text. With or without protocol. It matches against all toplevel domains to find the URL in the text. |
| Matches |
http://www.website.com/index.html | www.website.com | website.com |
| Non-Matches |
Works in all my tests. Does not capture protocol. |
| Author |
Rating:
James Johnston
|
| Title |
Test
Details
Pattern Title
|
| Expression |
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} |
| Description |
Very Simple Match for dotted Decimal IP address. Doesn’t Validate addresses |
| Matches |
192.168.1.1 | 10.2.234.1 | 66.129.71.122 |
| Non-Matches |
192.168.1 | 10.2.1234.1 | 66 129 71 122 |
| Author |
Rating:
David Tersigni
|
| Title |
Test
Details
Pattern Title
|
| Expression |
((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+) |
| Description |
Regular Expression matches any internet URLs. Used with the replace method it comes in very handy. |
| Matches |
http://www.aspemporium.com | mailto:dominionx@hotmail.com | ftp://ftp.test.com |
| Non-Matches |
www.aspemporium.com | dominionx@hotmail.com | bloggs |
| Author |
Rating:
Justin Saunders
|
| 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 |
\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-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
|
Displaying page
of
pages;
Items to