Useful Regular Expressions

1. Matching an URL

There are many regular expressions out there that match an URL, but this is the best I’ve found so far:
‘#((https?://|www\.)([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#

2. Match email

“/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i”

This entry was posted in PHP/MySQL. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.