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
Change page:   |    Displaying page 1 of 2 pages; Items 1 to 20

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