Results 1 to 11 of 11

Thread: (Any Language) Common Regex

Threaded View

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    (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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width