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?"

30 of 516 comments (clear)

  1. Here's One for Slashdot Stories! by Anonymous Coward · · Score: 4, Funny

    (Useful) Stupid * Tricks

    Yes sir, that will guarantee a front page story. You better head back to the drawing board if it doesn't fit that pattern. Next week: (Useful) Stupid Starcraft Tricks.

    1. Re:Here's One for Slashdot Stories! by Malevolent+Tester · · Score: 4, Funny

      Next week: (Useful) Stupid Starcraft Tricks.

      You can assign a building, building add-on, or a group of up to 12 units to a single key. To do this, select what you want to assign, then hold down Control and select a number on the keyboard between 0-9. Then, when you want to select what you assigned, simply press the number of the group that you want. Pressing a group number twice will center the screen on the group.

      --
      If you haven't made a developer cry, you've wasted a day.
    2. Re:Here's One for Slashdot Stories! by McWilde · · Score: 4, Funny

      That doesn't look right...
      Try:

      /^\(Useful\) Stupid \w+ Tricks$/

      Also, I noticed that the previous stupid tricks stories ended with a question mark, but this one doesn't. So:

      /^\(Useful\) Stupid \w+ Tricks\??$/

      --
      Maybe
    3. Re:Here's One for Slashdot Stories! by Anpheus · · Score: 2, Funny

      Did you get that from the tips that pop up every game when you first install StarCraft?

  2. End it all... by Notquitecajun · · Score: 1, Funny

    format c:*.*

  3. ARGH!!!! by soapdog · · Score: 2, Funny

    You see yourself in digg.com. You are likely to be eaten by a grue.

    --
    -- Por mais que eu ande no vale das trevas e da morte, meu PowerMac G4 Não Travará!!!
  4. How about by cbiltcliffe · · Score: 3, Funny

    Stupid (Useful) Ask Slashdot tricks?

    I'm not sure whether these are legitimate, or just a "I don't know what the hell I'm doing, so let's see if I can get someone else to show me how to do my job, under the guise of sharing information."

    I'd like to say the former, but my cynicism is making me lean to the latter.....

    --
    "City hall" in German is "Rathaus" Kinda explains a few things......
  5. Regex Bill by Anonymous Coward · · Score: 5, Funny

    Why couldn't Bill try out his regular expressions?

    His mom wouldn't let him play with matches.

  6. Nope, not useful by darkvizier · · Score: 4, Funny

    I've never found regexes to be useful at all. I prefer to write my own parsers from scratch in assembly language, or conway's game of life, if I'm feeling m/(ambitious|artistic|autistic|masochistic)/.

    But even an artist gets lazy sometimes.

  7. Re:IP and Hardware addresses by rallymatte · · Score: 5, Funny

    Not only are you showing off with a lower member id than me, do you also have to come up with a cooler regexp than me?

  8. Re:IP and Hardware addresses by alta · · Score: 4, Funny

    I can easily beat you on the UID, but I couldn't regex the a out of an apple.

    --
    Do not meddle in the affairs of sysadmins, for they are subtle, and quick to anger.
  9. Re:Regexp-based address validation by neoform · · Score: 4, Funny

    Best part of that Regex? It's easy to modify too!

    --
    MABASPLOOM!
  10. Re:IP and Hardware addresses by sqldr · · Score: 4, Funny

    Not only are you showing off with a lower member id than me

    Low ID = old fart. He may be a regexp wizard, but he probably looks like gandalf too :-D

    --
    I wrote my first program at the age of six, and I still can't work out how this website works.
  11. Re:IP and Hardware addresses by wertigon · · Score: 3, Funny

    Write a Regex for them! :D

    --
    systemd is not an init system. It's a GNU replacement.
  12. Re:some that I've used ... by jonaskoelker · · Score: 2, Funny

    ISO Date (19th to 21st century only)
    ^((18|19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])$

    This regexp is ISO certified. The certificate is valid until 2009-02-31.

  13. Re:IP and Hardware addresses by Dagger2 · · Score: 4, Funny

    That also fails beautifully with an address like "2001:db8:3c4d:48:a00:20ff:feb9:4c54", which is perfectly valid.

    Unless you know you're going to be dealing with numeric IPv4 addresses in a specific format, it would be best to pass them to getaddrinfo() (with AI_NUMERICHOST if you want to avoid DNS) and let somebody else worry about validating them properly.

  14. Search through phone numbers by cerberusss · · Score: 4, Funny
    This regex goes through my enormous list of girlfriends' telephone numbers, and makes a selection based on the area code I'm currently in!

    #$%^&*(&^%{{}}{/\/\||```

    (No, that's not a regex at all. And no, I don't even have a single girlfriend.)

    --
    8 of 13 people found this answer helpful. Did you?
  15. Re:IP and Hardware addresses by L4t3r4lu5 · · Score: 4, Funny

    That last bit is the perlre for a zero-width negative look-behind assertion

    It certainly looks like English, but I have no idea what that means. Whatever it is, it sure seems to help cure insomnia.

    --
    Finally had enough. Come see us over at https://soylentnews.org/
  16. Re:Match a library call number by mgbastard · · Score: 4, Funny

    holy crap. You DOCUMENTED your regular expression? You shall be thrown into the pit!

    --
    Anyone seen my low uid? last seen 10 years ago while panning the #@$# out of Taco's 'web based discussion system'
  17. Re:Regexp-based address validation by noidentity · · Score: 2, Funny

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

    And as a bonus, it can be used as a source of random bits, after base-64 decoding.

  18. Re:IP and Hardware addresses by glavenoid · · Score: 2, Funny

    No point, really. You old timers always seem to come out of the woodwork whenever low-UIDs come up in conversation :-)

    --
    I, for one, am looking forward to the inevitable /. beta rollout fallout.
  19. Re:Mainframe Formatting by angrytuna · · Score: 2, Funny

    That was a new one on me; I hadn't encountered that award before. Would something like:

    <REPORT_NAME sed 's/[^a-z0-9,.-]//gi' > REPORT.out

    be preferable in this instance?

    --

    It is a solemn thought: dead, the noblest man's meat is inferior to pork.

  20. The most useful regex there is! by ShatteredArm · · Score: 4, Funny

    I came up with a Regex that can be used to match literally anything (yes, anything!). It is, therefore, the most flexible regex ever concocted. Here it is:

    .*

    1. Re:The most useful regex there is! by Lord+Ender · · Score: 2, Funny

      I was able to simplify your regex somewhat so that it still matches everything, but takes up half the space:

      .

      --
      A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
  21. Re:IP and Hardware addresses by Vadim+Grinshpun · · Score: 4, Funny

    Hmmm... until recently I didn't even realize that low ID's were in vogue :)

  22. Re:IP and Hardware addresses by jez9999 · · Score: 2, Funny

    You think THAT'S cool? I've seen CMDRTACO posting! Now that was a sight to behold. Actually I think I even saw a -1 once, which was his mom.

  23. It must be said by IorDMUX · · Score: 3, Funny

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

    -- Jamie Zawinski

    --
    >> Standing on head makes smile of frown, but rest of face also upside down.
  24. Re:IP and Hardware addresses by mikiN · · Score: 4, Funny

    You must be new h... (looks at PP's ID, gasps)
    Nevermind.

    --
    The Hacker's Guide To The Kernel: Don't panic()!
  25. Re:IP and Hardware addresses by Kymermosst · · Score: 3, Funny

    So, would anyone like to buy my new T-shirt, it says "There is no place like 2130706433."

    --
    "Alcohol, Tobacco, Firearms, and Explosives" should be a convenience store, not a government agency.
  26. Re:IP and Hardware addresses by morgan_greywolf · · Score: 2, Funny

    I'd rather take issue with the fact it completely fails on IPv6 addresses.

    Wake me up when that actually matters, k?