Results 1 to 11 of 11

Thread: (Any Language) Common Regex

  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

  2. #2
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: (Any Language) Common Regex

    Wow, nice post! I needed this! Thanks!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  3. #3

  4. #4

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

    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.

  5. #5
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    968

    Re: (Any Language) Common Regex

    Hi m8 ,

    Can you give a quick sample on how to actually use this in a project/Form.

    Thanks

  6. #6

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

    Re: (Any Language) Common Regex

    Here's a demo project.
    Attached Files Attached Files

  7. #7
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    968

    Re: (Any Language) Common Regex

    Thnaks alot minitech.

  8. #8

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

    Re: (Any Language) Common Regex

    Update to e-mail address:
    Code:
    ^[a-zA-z0-9_\-\.]+@[a-zA-z0-9_\-\.]+?\.\w{2,4}$

  9. #9
    Lively Member
    Join Date
    May 2008
    Posts
    113

    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

  10. #10

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

    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*

  11. #11

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

    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
  •  



Click Here to Expand Forum to Full Width