#1
  1. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Sep 2007
    Location
    outside Washington DC
    Posts
    2,642
    Rep Power
    3699

    Gotta see today's XKCD


    http://www.xkcd.com/1171/
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    Think i have seen the similar "joke" in someone signature.

    What is it that makes regular expression so bad? performance?
  4. #3
  5. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    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.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,961
    Rep Power
    9397
    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.
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    Want to comment at my question too?
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,961
    Rep Power
    9397
    That can be answered with another 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)...
  12. #7
  13. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    828
    Rep Power
    496
    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. ;-)

IMN logo majestic logo threadwatch logo seochat tools logo