The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Gotta see today's XKCD
Discuss Gotta see today's XKCD in the Regex Programming forum on Dev Shed. Gotta see today's XKCD Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 8th, 2013, 08:28 PM
|
 |
Contributing User
|
|
Join Date: Sep 2007
Location: outside Washington DC
|
|
|
Gotta see today's XKCD
http://www.xkcd.com/1171/
|

February 9th, 2013, 05:18 AM
|
 |
Lord of the Dance
|
|
|
|
|
Think i have seen the similar "joke" in someone signature.
What is it that makes regular expression so bad? performance?
|

February 11th, 2013, 08:07 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
Quote: | Originally Posted by MrFujin Think i have seen the similar "joke" in someone signature.
|
You have indeed. Axweildr has had a related quote in his sig for years.
|

February 11th, 2013, 12:31 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by ishnid You have indeed. Axweildr has had a related quote in his sig for years. |
I figured the comic was a play on that too.
|

February 11th, 2013, 01:18 PM
|
 |
Lord of the Dance
|
|
|
|
Want to comment at my question too? 
|

February 11th, 2013, 02:36 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
That can be answered with another quote.
Quote: | When all you have is a hammer, everything looks like a nail. |
More seriously, people learn this cool new thing called "regular expressions" and try to come up with situations where they can use it. Even if it's just to show off. Even if regular string parsing or DOM traversal or something else more appropriate (and correct) exists. And half the time these people have a decent, not complete, understanding: no sense of optimizations, don't understand how greedy quantifiers work with the engine, think that an expression they have which works on their sample input will necessarily work for every other input (valid or otherwise)...
|

February 11th, 2013, 05:09 PM
|
 |
Lord of the Dance
|
|
|
|
Ok, that makes sense and clarified that it is more about be able to "use the correct tool to the correct job" instead of the tool itself.
Would say I have great use of regex in notepad++, but must probably also admit that half of the reason is in the "fun" to find out if it can be done this way. 
I'm usually using regex to wrap same text or similar that have to applied around several lines of text.
|

February 11th, 2013, 05:43 PM
|
|
|
Quote: | Originally Posted by requinix
More seriously, people learn this cool new thing called "regular expressions" and try to come up with situations where they can use it. Even if it's just to show off. Even if regular string parsing or DOM traversal or something else more appropriate (and correct) exists. And half the time these people have a decent, not complete, understanding: no sense of optimizations, don't understand how greedy quantifiers work with the engine, think that an expression they have which works on their sample input will necessarily work for every other input (valid or otherwise)... |
I totally agree with this, and probably most people discovering the power of regexes tend at one point or another to try to overuse them, or abuse them, or use them where there are much better tools, but once you really understand them (including issues of greediness, eagerness, etc.), and also know other tools available in the language or environment you are using, regex are a tremendous tool at your disposal when they are available. They should not be used for things for which they are not fit (they are not a good substitute for a real parser, for example, and should generally not be used for parsing XML or HTML files, for example), but they are immensely useful for doing the things for which they are fit.
And performance is certainly not a good reason not to use them, unless you really have a performance issue (and provided you are using regexes in a good way). I am working almost daily with huge files (10 or 15 gigabytes, sometimes even 10 to 20 times larger) and am happily using Perl regexes on them, when they are fit to the purpose. A very very poorly designed regex can take billions of years to match (or not match) just a single line of input (well, actually, I guess you really have to do it on purpose to reach such a bad result, but the point is that it is possible), but a good regex can also analyze hundreds of million lines in a few minutes.
In brief, regexes are an excellent tool for some purposes, and may be a disaster for others.
An additional point about performance. If you are working on relatively small data input (in my perspective, 100 megabytes is often small), ask yourself the question whether it is worth spending hours of valuable developer's time for winning a few seconds of processing time. Usually not (but, in rare cases, yes). So, if regexes enable you to write the really useful part of a program in 3 lines of codes, rather than 300 lines (meaning development times 10 or 100 times shorter), it is quite likely to be the right way to go unless you really have difficult processing time constraints.
I think there is nothing special about regexes: sometimes there are the right tool, sometimes not. Just as, sometimes, you need an array, sometimes an hash, sometimes a binary tree or some other complex data structure. Or, sometimes, you just want to use shell script or Javascript, sometimes a more complete language like Perl, Python, PHP or Ruby (and possibly TCL) is more appropriate, sometimes Java or C++ will be needed for higher performance, and sometimes, you'll need the power of pure C or even assembler (last time I had to use some assembler was in 1996, if I remember correctly, I hope this will not happen again. ;-)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|