Slashdot Mirror


(Useful) Stupid Regex Tricks?

careysb writes to mention that in the same vein as '*nix tricks' and 'VIM tricks', it would be nice to see one on regular expressions and the programs that use them. What amazingly cool tricks have people discovered with respect to regular expressions in everyday life as a developer or power user?"

4 of 516 comments (clear)

  1. Regexp-based address validation by mutende · · Score: 5, Informative

    Beautiful regexp that validates RFC 822 addresses: Mail-RFC822-Address.html

    --
    Unselfish actions pay back better
  2. Re:IP and Hardware addresses by Richard_J_N · · Score: 5, Informative

    Of course, you can do better still. For mac addresses, try:
        ^([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}$
    [:xdigit:] is short for hexadecimal digits, i.e. a-fA-F0-9
    We can also loop 5 times over the 'XX:' sections.

  3. Re:IP and Hardware addresses by Speare · · Score: 5, Informative

    For pretty much any useful stock problem solved by regular expressions, see Perl's Regex::Common module. A lot of these patterns are fiendishly complicated to deal with edge-cases properly.

    --
    [ .sig file not found ]
  4. Do these questions really belong here? by DerCed · · Score: 5, Informative

    I wonder why such FAQs are still posted on a site like Slashdot. We now have a great repository for exactly this kind of questions:
    http://stackoverflow.com/questions/tagged?tagnames=regex&sort=votes&pagesize=15