RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

Change page:   |    Displaying page 1 of 2 pages; Items 1 to 20
Title Test Details UK Postcode District
Expression
([A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw]))
Description
Matches the first part of a UK Postcode (known as a postcode district). Case insensitive. Doesnt match: GIR # the postcode for the formerly Post Office-owned Girobank is GIR 0AA. SAN # the postcode for correctly addressed letters to Father Christmas is SAN TA1
Matches
LN5 | SW1 | ln5
Non-Matches
ln5 7nq | GIR | SAN
Author Rating: The rating for this expression. Matthew Harris
Title Test Details Clean Domain Name
Expression
^http\://www.[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}/$
Description
This regex only matches clean domain names. No path after. Ends in a forward slash. Starts with http://www. It is pretty slack on the TLD requiring a 2 or 3 letter ending. This part could be tightened up if you wanted to be restrict it to specific TLDs.
Matches
http://www.somedomain.co.uk/ | http://www.somedomain.com/ | http://www.dodgydomain.com.com/
Non-Matches
http://www.somedomain.co.uk/withpath.aspx | http://somedomainwithoutwww.co.uk | http://www.com/ | www.noprotocolprefix.com/ | https://www.secureprotocolprefix.com/ | http://www.notrailingslash.co.uk | HTTP://WWW.beginswithcaps.com/
Author Rating: The rating for this expression. Matthew Harris
Title Test Details UK Phone Number in 4-3-4 Format
Expression
^[\d]{4}[-\s]{1}[\d]{3}[-\s]{1}[\d]{4}$
Description
Allows dashes or spaces to separate.
Matches
0800 333 4444 | 0870-333-4444 | 0844 333-4444
Non-Matches
08003334444 | 0800=333=4444 | 0800 333 4444
Author Rating: The rating for this expression. Matthew Harris
Title Test Details UK Phone Number in 5-3-3 Format
Expression
^[\d]{5}[-\s]{1}[\d]{3}[-\s]{1}[\d]{3}$
Description
Allows dashes or spaces to separate.
Matches
08000 333 333 | 08700-333-333 | 08440 333-333
Non-Matches
08000333333 | 08000=333=333 | 08000 333 333
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Phone Number in 5-2-2-2 Format
Expression
^[\d]{5}[-\s]{1}[\d]{2}[-\s]{1}[\d]{2}[-\s]{1}[\d]{2}$
Description
Allows dashes or spaces to separate.
Matches
08000 22 22 22 | 08700-22-22-22 | 08440 22-22-22
Non-Matches
08000222222 | 08000=22=22=22 | 08000 22 22 22
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Phone Number in 5-4-2 Format
Expression
^[\d]{5}[-\s]{1}[\d]{4}[-\s]{1}[\d]{2}$
Description
Allows dashes or spaces to separate.
Matches
0800 4444 22 | 0870-4444-22 | 0844 4444-22
Non-Matches
0800444422 | 0800=4444=22 | 0800 4444 22
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Phone Number in 5-2-4 Format
Expression
^[\d]{5}[-\s]{1}[\d]{2}[-\s]{1}[\d]{4}$
Description
Allows dashes or spaces to separate.
Matches
0800 22 4444 | 0870-22-4444 | 0844 22-4444
Non-Matches
0800224444 | 0800=22=4444 | 0800 22 4444
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Bank Sort Code
Expression
^(\d){2}-(\d){2}-(\d){2}$
Description
Validates the format of a UK bank sort code.
Matches
20-40-36 | 50-25-48 | 45-85-66
Non-Matches
204036 | 2564584 | 444-58-54 | 45/45/85
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Bank Account (8 Digits)
Expression
^(\d){8}$
Description
UK Bank account numbers are 8 digits. One bank uses 7 digits so in the validation error message you should instruct the user to prefix with a zero of their code is too short. If you want to allow the 7 digit codes as well use this regex: http://regexlib.com/REDetails.aspx?regexp_id=2707
Matches
08464524 | 45832484 | 24899544
Non-Matches
1234567 | 1 5 2226 44 | 123456789
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Bank Account (7-8 Digits)
Expression
^(\d){7,8}$
Description
UK Bank Account. One bank account issues 7 digit bank codes and you should prefix a 0 yourself after input. If you want strict validation of 8 characters use this regex: http://regexlib.com/REDetails.aspx?regexp_id=2706
Matches
1234567 | 12345678
Non-Matches
123456 | 123 4567 | 123456789
Author Rating: Not yet rated. Matthew Harris
Title Test Details No Whitespace
Expression
^[^\s]+$
Description
No whitespace is allowed in a string
Matches
nowhitespace | onewordonly | anotherexample
Non-Matches
two words | three words here | anything with spaces
Author Rating: Not yet rated. Matthew Harris
Title Test Details Up to 15 digits followed by 0,1 or 2 floating points
Expression
^[0-9]{1,15}(\.([0-9]{1,2}))?$
Description
This might seem like a contrived example but it was written to answer a question on a forum. For regex newbies you can just change the numbers in {} to change the number of required digits to suit your requirements
Matches
1 | 123456789012345 | 123456789012345.1 | 123456789012345.12 | 123456.12
Non-Matches
.12 | 12345.123 | 1234567890123456
Author Rating: The rating for this expression. Matthew Harris
Title Test Details 1 to 99 in .5 increments
Expression
^[1-9]{1,2}(.5)?$
Description
This is a simple regular expression which allows 1 to 99 in .5 increments which I originally developed for a forum post
Matches
1.5 | 99.5 | 35.5 | 43 | 64 | 24
Non-Matches
.5 | 100 | 0 | 0.5 | 34.3 | 24.356 | 36.55
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Landline including VOIP
Expression
^(02\d\s?\d{4}\s?\d{4})|((01|05)\d{2}\s?\d{3}\s?\d{4})|((01|05)\d{3}\s?\d{5,6})|((01|05)\d{4}\s?\d{4,5})$
Description
Based on the source listed below. I have added in the 05 prefix for allowing UK voip landlines. I dont know if the spacings are all ofcom approved like the original regex but the patterns it supports are: 029 99999999 or 029 9999 9999; 0199 9999999 or 0199 999 9999; 01999 99999; 01999 999999; 019999 9999; 019999 99999; 0599 9999999 or 0599 999 9999; 05999 99999; 05999 999999; 059999 9999; 059999 99999;
Matches
020 1234 5678 | 0123 4567890 | 01234 456789 | 05234 456789
Non-Matches
02476 123456 | 0845 123456 | 07712 345678 | 0800 100 2496
Author Rating: Not yet rated. Matthew Harris
Title Test Details IPv4, udp/norm protocol with port
Expression
^(udp|norm)://(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}:\d{1,6}$
Description
Based on ip regex listed in source. Expanded to require udp:// or norm:// protocol at the start and :12345 port number at the end (1-5 digits). Written to answer a forum question. Current limitations - only allows lowercase protocol names and doesn't block ports that start with 0.
Matches
norm://125.24.65.11:80 | udp://125.24.65.11:80
Non-Matches
125.24.65.11:80 | norm://125.24.65.11 | www.NotAnIp.com
Author Rating: Not yet rated. Matthew Harris
Title Test Details Validate IP port number (1-65535)
Expression
:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})
Description
This was based on the regex in the source but it was buggy so I fixed it and then optimized it. It matches port numbers in the form of :1 to :65535 This is designed to be plugged onto the end of your favourite url regex because when I was looking for a IPv4 regex I noticed that a lot of them either didn't match the port or matched it badly (allowing the port number to start with a 0 or be higher than 65535) This regex solves those two problems.
Matches
:1 | :65535 | :2546
Non-Matches
:99999 | :0684 | :2ab23
Author Rating: Not yet rated. Matthew Harris
Title Test Details Validate optional IP port number (1-65535)
Expression
(:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}))?
Description
This is the same as my regex listed in the source except that it is wrapped in (regex)? which makes it optional. The intended use for this regex is to be combined with buggy url/ip regex's to strengthen the port matching. It matches port numbers in the form of :1 to :65535 and also allows no port to be entered. I noticed that a lot of url/ip regexs either didn't match the port or matched it badly (allowing the port number to start with a 0 or be higher than 65535) This regex solves those two problems.
Matches
:1 | :65535 | :2546 | no port entered
Non-Matches
:99999 | :0684 | :2ab23
Author Rating: Not yet rated. Matthew Harris
Title Test Details Active Directory User@Domain Format
Expression
^(?<user>.+)@(?<domain>.+)$
Description
This uses named groups to extract the user and domain portions of an Active Directory user in user@domain format. You can use the following c# code to convert this into domain\user format: public string ConvertUserAtDomainToDomainUser(string userAtDomain) { return Regex.Replace(userAtDomain, @"^(?<user>.+)@(?<domain>.+)$", @"${domain}\${user}"); } This regex is intended to provide extraction from valid user@domain strings rather than validate its format.
Matches
bill@microsoft | peter.gibbons@initech | blackbeard@jollyroger
Non-Matches
bil+microsoft | microsoft\bill
Author Rating: Not yet rated. Matthew Harris
Title Test Details YouTube Video ID Extraction
Expression
http://www\.youtube\.com.*v=(?'VideoID'[^&]*)
Description
This will match a youtube url and pull the video id out into a named capture group called VideoID. It is intentionally loose on the length and content of the video id so that it doesn't break in the future if YouTube change the format.
Matches
http://www.youtube.com/watch?gl=GB&feature=topvideos&hl=en-GB&v=tin6gKecb8k | http://www.youtube.com/watch?gl=GB&feature=topvideos&v=tin6gKecb8k&hl=en-GB | http://www.youtube.com/watch?v=tin6gKecb8k
Non-Matches
http://www.youtube.com/ | http://www.othersite.com/ | http://www.youtube.com/watch?gl=GB
Author Rating: Not yet rated. Matthew Harris
Title Test Details Validate Twitter Account Url
Expression
^http[s]?://twitter\.com/(#!/)?[a-zA-Z0-9]{1,15}[/]?$
Description
Allows http and https, bans www prefix, username portion is clamped to the rules it gives you at signup and also allows an optional trailing slash. [UPDATED] allows the #! notation that twitter used.
Matches
http://twitter.com/rtpharry/ | http://twitter.com/rtpharry | https://twitter.com/rtpharry/ | https://twitter.com/rtpharry | http://twitter.com/#!/rtpharry/
Non-Matches
http://www.twitter.com/wwwprefix/ | http://twitter.com/longerthan15characters/ | http://twitter.com/illegal$chars/
Author Rating: Not yet rated. Matthew Harris
Title Test Details Facebook Pages
Expression
http[s]?://(www|[a-zA-Z]{2}-[a-zA-Z]{2})\.facebook\.com/(pages/[a-zA-Z0-9\.-]+/[0-9]+|[a-zA-Z0-9\.-]+)[/]?$
Description
Validating a Facebook page can be a little bit tricky. This is because there are two valid formats. The first is facebook.com/pages/USERNAME/numbers/, the second is designed for big business which grants them a clean url such as facebook.com/coca-cola/. I see this regex being used in a user profile admin page and I think it does a good enough job for this purpose. The problem is bad urls could slip through which meet the criteria for the clean facebook page url but aren't in valid pages on the site. The main example being that an incomplete numbered url could slip through as http://www.facebook.com/pages/ would validate. Facebook also uses various subdomains such as en-gb.facebook.com to provide localised versions of the site. This regex will accept a prefix of either www or a locale code of two letters dash two letters. It doesn't validate the actual country code though. [UPDATED] Added full stop to list of valid characters for page names.
Matches
http://www.facebook.com/pages/Andy-Worthington/196377860390800 | http://en-gb.facebook.com/pages/Andy-Worthington/196377860390800 | http://www.facebook.com/pages/ | http://www.facebook.com/coca-cola/ | http://www.facebook.com/thesimpsons/
Non-Matches
http://facebook.com/pages/Andy-Worthington/196377860390800 | www.facebook.com/pages/Andy-Worthington/196377860390800 | http://www.facebook.com/people/Andy-Worthington/738143803
Author Rating: The rating for this expression. Matthew Harris
Title Test Details Allow digits but exclude certain numbers
Expression
^(?!^(5|15|18|30)$)\d+$
Description
Because a regular expression only deals with a single character at a time it can be a challenge to work with numbers as they often contain multiple digits. This regex allows any number except the numbers in the list. It does this by using a negative look ahead to fail the regex if it finds an excluded number.
Matches
1 | 325 | 515 | 300
Non-Matches
5 | 15 | 18 | 30
Author Rating: Not yet rated. Matthew Harris
Title Test Details Google Analytics Account Id
Expression
^UA-\d+-\d+$
Description
This is an intentionally loose implementation. The number in the middle (account num) is constantly increasing as new accounts are made. The number on the end represents the profile number which shouldn't go over 50 but I haven't locked this down so that both elements are future proofed.
Matches
UA-686645-1 | UA-71354555-50 | UA-1-1
Non-Matches
UA-686645-1DD | UA-68DD6645-1 | GA-686645-1
Author Rating: Not yet rated. Matthew Harris
Title Test Details Optional Querystring
Expression
(?:\?=.*)?$
Description
Add this on to the end of your url rewriting regex to allow an optional querystring to be appended to whatever you are matching. Useful for example when you set up a Google PPC campaign and all of your urls break. Note: doesn't handle #fragments.
Matches
?with=querystring | | ?with=multiple&query=strings
Non-Matches
?with=querystring#fragment
Author Rating: Not yet rated. Matthew Harris
Title Test Details Match Default Document + Optional Querystring
Expression
^~/(?:default\.aspx)?(?:\?=.*)?$
Description
Designed for asp.net default document matching. It allows either a plain url (~/) or a default document url (~/default.aspx) both with an optional querystring. Cassini and IIS7 handle default document matching differently. The user could type it either way. The breadcrumb / sitemap system is funny about omitting default.aspx. Note: Doesn't handle #fragements
Matches
/default.aspx | /default.aspx?query=string | / | /?query=string
Non-Matches
/default.aspx#fragment | /default.aspx?query=string#fragment | /#fragment | /?query=string#fragment
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Postcode District (Loose Match)
Expression
[A-Za-z]{1,2}[\d]{1,2}[A-Za-z]{0,1}
Description
The postcode district is the first block of a UK postcode. For example with DN55 1PT it would match DN55. Its a loose match as it only ensures that the format is correct, it doesn't validate the letters and numbers. It doesn't let in the non-geographic codes postcodes SAN TA1 and GIR 0AA. It will pull out the first block of any of the matching examples below. Examples of the names of the different parts of a UK postcode can be found here: http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Life-cycle_of_post_codes
Matches
AA9A 9AA | A9A 9AA | A9 9AA | A99 9AA | AA9 9AA | AA99 9AA | EC1A 1BB | W1A 1HQ | M1 1AA | B33 8TH | CR2 6XH | DN55 1PT
Non-Matches
SAN TA1 | GIR 0AA
Author Rating: Not yet rated. Matthew Harris
Title Test Details UK Postcode Sector (Loose Match)
Expression
[A-Za-z]{1,2}[\d]{1,2}[A-Za-z]{0,1}\s*[\d]
Description
The postcode sector is the first block (the postcode district) of a UK postcode plus the first number of the second block. For example with DN55 1PT it would match DN55 1. Its a loose match as it only ensures that the format is correct, it doesn't validate the letters and numbers. It doesn't let in the non-geographic codes postcodes SAN TA1 and GIR 0AA. It will pull out the first block & the sector code of any of the matching examples below. Examples of the names of the different parts of a UK postcode can be found here: http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Life-cycle_of_post_codes
Matches
AA9A 9AA | A9A 9AA | A9 9AA | A99 9AA | AA9 9AA | AA99 9AA | EC1A 1BB | W1A 1HQ | M1 1AA | B33 8TH | CR2 6XH | DN55 1PT | AA9A9AA | A9A9AA | A99AA | A999AA | AA99AA | AA999AA
Non-Matches
SAN TA1 | GIR 0AA
Author Rating: Not yet rated. Matthew Harris
Title Test Details Parcelforce - UK tracking code
Expression
^([A-z]{2}\d{7})|([A-z]{4}\d{10})$
Description
UK Parcelforce delivery tracking code for internal UK posts. Comes in two formats 2 letters and 7 numbers (e.g. AA1234567) and 4 letters and 10 numbers (e.g. AAAA1234567890). Case insensitive.
Matches
AA1234567 | AAAA1234567890
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details Parcelforce - International tracking of exports
Expression
^([A-z]{2}\d{9}[Gg][Bb])|(\d{12})$
Description
UK Parcelforce delivery tracking code for international tracking of exports. Comes in two formats: 2 letters and 9 numbers and GB (e.g. AA123456789GB) and 12 numbers (e.g. 123456789012). Case insensitive.
Matches
AA123456789GB | 123456789012
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details Parcelforce - International tracking of imports
Expression
^[A-z]{2}\d{9}(?![Gg][Bb])[A-z]{2}$
Description
UK Parcelforce delivery tracking code for international tracking of imports. Uses a negative look ahead to prevent it ending in GB which would be an international export code.
Matches
AA123456789AA
Non-Matches
AA123456789GB | AA123456789gb | AA123456789Gb | AA123456789gB
Author Rating: Not yet rated. Matthew Harris
Title Test Details Parcelforce - All Tracking Codes
Expression
^(?<ParcelForceUK>(?:[A-z]{2}\d{7})|(?:[A-z]{4}\d{10}))$|^(?<ParcelForceExport>(?:[A-z]{2}\d{9}[Gg][Bb])|(?:\d{12}))$|^(?<ParcelForceImport>[A-z]{2}\d{9}(?![Gg][Bb])[A-z]{2})$
Description
A combined version of my other three Parcelforce tracking code regexes listed on this site. Uses named capture groups to capture and identify between UK tracking, international export and international import tracking codes. Case insensitive.
Matches
AA1234567 | AAAA1234567890 | AA123456789GB | 123456789012 | AA123456789AA
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details TNT UK Delivery Tracking Code
Expression
^(?:[A-z]{2})?\d{9}(?:[A-z]{2})?$
Description
TNT UK delivery company consignment number tracking code for TNT Track and Trace service. The system will use the 9 digit code (e.g. 123456789) or you can use the letters as shown on your consignment note (e.g. GE123456781WW). Case insensitive.
Matches
123456789 | GE123456781WW
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details UPS - United States format
Expression
^(?:1[Zz])(?<ShipperNumber>[A-z\d]{6})(?<ServiceCode>[A-z\d]{2})(?<PackageId>\d{8})$
Description
Uses named capture groups to extract components. More information on the components meanings can be found on the wikipedia page list in the source.
Matches
1z5475953256813457 | 1Z9999999999999999
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details UPS - UK format
Expression
^((1[Zz]\d{16})|(\d{12})|([Tt]\d{10})|(\d{9}))$
Description
As listed in on the UK UPS tracking help page (listed in the source)
Matches
1Z9999999999999999 | 999999999999 | T9999999999 | 999999999
Non-Matches
non | matching | examples
Author Rating: Not yet rated. Matthew Harris
Title Test Details S10 (UPU Standard) Parcel Tracking Code
Expression
^(?<ServiceCode>[A-z]{2})(?<ParcelNumber>\d{8})(?<CheckDigit>\d{1})(?<IsoCountryCode>[A-z]{2})$
Description
Uses named capture groups to parse an S10 (UPU standard) code which is the tracking format used by many postal services including the United States Postal Service and most European Postal Services. Full spec in source link.
Matches
AA473124829GB
Non-Matches
non | matching | examples
Author Rating: The rating for this expression. Matthew Harris
Change page:   |    Displaying page 1 of 2 pages; Items 1 to 20

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials