Nov 2nd, 2009, 06:38 PM
#1
Thread Starter
Stack Overflow moderator
(Any Language) Common Regex
Everyone seems to be asking for these in the forum, so here are some common ones that will match anything valid.
E-mail:
Code:
^[a-zA-z0-9_\-\.]+@[a-zA-z0-9_\-\.]+?\.\w{2,4 }$
URL:
Code:
^((http|ftp)s?://)?[a-zA-z0-9_\-\.]+?\.\w{2,3}(:\d{2,5})?(/[a-zA-z0-9_\-\.]*)*
Phone Number:
Code:
^(\d*(\-\s*)?)?((\(\d{3}\)\s*)|(\d{3}\s*(\-\s*)?))?\d{3}\s*(\-\s*)?\d{4}$
Image Source File (from HTML):
Code:
(?<=\<img\s.*?src=['"])[^"']+
IP Address with Optional Port Number:
Code:
(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?
New ones on request by PM or post.
Last edited by minitech; Jun 24th, 2010 at 08:34 PM .
Reason: Added IP Address
Nov 3rd, 2009, 11:45 PM
#2
Fanatic Member
Re: (Any Language) Common Regex
Wow, nice post! I needed this! Thanks!
Nov 4th, 2009, 05:27 AM
#3
Re: (Any Language) Common Regex
An example of what the regex matches would be nice Email and possibly URL are obvious, but phone number isn't (not every part of the world uses the same phone number layout ).
Nov 4th, 2009, 12:10 PM
#4
Thread Starter
Stack Overflow moderator
Re: (Any Language) Common Regex
Phone number matches Canadian & US phone number. I don't really know any other format, sorry! It will match anything like this:
12501234567 (Country code, area code, local phone #, no formatting.)
(250) 123-4567
250 123 4567
2501234567
123-4567
1-250-463-4448
etc. I tried to make the Regex so that they match all possible combinations for what they're used for.
Feb 19th, 2010, 08:12 PM
#5
Fanatic Member
Re: (Any Language) Common Regex
Hi m8 ,
Can you give a quick sample on how to actually use this in a project/Form.
Thanks
Feb 19th, 2010, 08:41 PM
#6
Thread Starter
Stack Overflow moderator
Re: (Any Language) Common Regex
Attached Files
Feb 20th, 2010, 11:56 AM
#7
Fanatic Member
Re: (Any Language) Common Regex
Apr 22nd, 2010, 01:41 PM
#8
Thread Starter
Stack Overflow moderator
Re: (Any Language) Common Regex
Update to e-mail address:
Code:
^[a-zA-z0-9_\-\.]+@[a-zA-z0-9_\-\.]+?\.\w{2,4}$
Jun 24th, 2010, 06:19 PM
#9
Lively Member
Re: (Any Language) Common Regex
minitech,
Im trying to scrape proxy ips from a web page
http://proxies.my-proxy.com/proxy-list-s1.html
what would be the solution for this.
Many thanks
Jun 24th, 2010, 08:32 PM
#10
Thread Starter
Stack Overflow moderator
Re: (Any Language) Common Regex
That would be:
Code:
(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?
For IP address w/ optional port. *added*
Jun 24th, 2010, 08:54 PM
#11
Thread Starter
Stack Overflow moderator
Re: (Any Language) Common Regex
Oh, and one for extracting MD5 hashes prefixed with MD5: :
Code:
(?<=MD5\:[^a-fA-F0-9]*)[a-fA-F0-9]+
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width