(Useful) Stupid Regex Tricks? 516
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?"
Here's One for Slashdot Stories! (Score:4, Funny)
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.
End it all... (Score:2, Funny)
ARGH!!!! (Score:2, Funny)
How about (Score:4, 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.....
Regex Bill (Score:5, Funny)
His mom wouldn't let him play with matches.
Nope, not useful (Score:5, Funny)
But even an artist gets lazy sometimes.
Re:IP and Hardware addresses (Score:5, Funny)
Re:Here's One for Slashdot Stories! (Score:5, 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.
Re:Here's One for Slashdot Stories! (Score:5, Funny)
That doesn't look right...
Try:
Also, I noticed that the previous stupid tricks stories ended with a question mark, but this one doesn't. So:
Re:IP and Hardware addresses (Score:5, Funny)
Re:Regexp-based address validation (Score:5, Funny)
Best part of that Regex? It's easy to modify too!
Re:IP and Hardware addresses (Score:5, Funny)
Low ID = old fart. He may be a regexp wizard, but he probably looks like gandalf too
Re:IP and Hardware addresses (Score:3, Funny)
Re:some that I've used ... (Score:3, 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.
Re:IP and Hardware addresses (Score:4, Funny)
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.
Search through phone numbers (Score:5, Funny)
#$%^&*(&^%{{}}{/\/\||```
(No, that's not a regex at all. And no, I don't even have a single girlfriend.)
Re:IP and Hardware addresses (Score:5, 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.
Re:Match a library call number (Score:5, Funny)
Re:Regexp-based address validation (Score:2, Funny)
And as a bonus, it can be used as a source of random bits, after base-64 decoding.
Re:IP and Hardware addresses (Score:3, Funny)
Re:Mainframe Formatting (Score:2, Funny)
That was a new one on me; I hadn't encountered that award [sial.org] before. Would something like:
<REPORT_NAME sed 's/[^a-z0-9,.-]//gi' > REPORT.out
be preferable in this instance?
The most useful regex there is! (Score:5, Funny)
Re:Here's One for Slashdot Stories! (Score:3, Funny)
Did you get that from the tips that pop up every game when you first install StarCraft?
Re:IP and Hardware addresses (Score:4, Funny)
Hmmm... until recently I didn't even realize that low ID's were in vogue :)
Re:The most useful regex there is! (Score:3, Funny)
I was able to simplify your regex somewhat so that it still matches everything, but takes up half the space:
.
Re:IP and Hardware addresses (Score:3, 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.
It must be said (Score:4, Funny)
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Re:IP and Hardware addresses (Score:4, Funny)
You must be new h... (looks at PP's ID, gasps)
Nevermind.
Re:IP and Hardware addresses (Score:4, Funny)
So, would anyone like to buy my new T-shirt, it says "There is no place like 2130706433."
Re:IP and Hardware addresses (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?