(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. :)
Re: (Any Language) Common Regex
Wow, nice post! I needed this! Thanks!
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 ;) ).
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.
Re: (Any Language) Common Regex
Hi m8 ,
Can you give a quick sample on how to actually use this in a project/Form.
Thanks
1 Attachment(s)
Re: (Any Language) Common Regex
Re: (Any Language) Common Regex
Re: (Any Language) Common Regex
Update to e-mail address:
Code:
^[a-zA-z0-9_\-\.]+@[a-zA-z0-9_\-\.]+?\.\w{2,4}$
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
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*
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]+