• (cs)

    You know, I'm fairly certain that Regular Expressions could cook breakfast for me if I could figure out the right sequence.

  • parser (unregistered)

    considering that
    is just as legal.. oh well.

  • parser (unregistered) in reply to parser
    parser:
    considering that
    is just as legal.. oh well.
    that is,
  • parser (unregistered) in reply to parser
    parser:
    considering that
    is just as legal.. oh well.
    ..that is,
    separated by any number of spaces.
  • Jon B (unregistered)

    He's lucky the tag isn't <line break goes here>

  • (cs)

    As awesome as regular expressions are, they aren't taught in most Comp Sci programs. This looks more like a task one would assign to a junior developer, and provide some guidance to them, or a suggestion of what to use. Now, if you were to tell me this was done by a senior engineer, or provided some history of grandiose accomplishments from the perpetrator of this submission, perhaps I would be more awestruck by it's "wtf"-osity. As it stands, it just appears to be an individual unaware of one of the many tools available to a developer.

  • (cs)

    Oops...

  • (cs) in reply to cBradley
    cBradley:
    As awesome as regular expressions are, they aren't taught in most Comp Sci programs. This looks more like a task one would assign to a junior developer, and provide some guidance to them, or a suggestion of what to use. Now, if you were to tell me this was done by a senior engineer, or provided some history of grandiose accomplishments from the perpetrator of this submission, perhaps I would be more awestruck by it's "wtf"-osity. As it stands, it just appears to be an individual unaware of one of the many tools available to a developer.
    What CS program did you have that didn't include regex? We had to learn the language theory and design our own regex engine.
  • Fuji (unregistered) in reply to Tukaro
    Tukaro:
    You know, I'm fairly certain that Regular Expressions could cook breakfast for me if I could figure out the right sequence.

    It could, but the eggs would always look like they are scrambled.

  • dkf (unregistered) in reply to cBradley
    cBradley:
    As awesome as regular expressions are, they aren't taught in most Comp Sci programs.
    You mean there's a lot of places affiliated with WTF-U's programme? What are they teaching instead, underwater basket-weaving?
  • tomanyregex (unregistered)

    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

  • (cs)
    strTagLess = Replace(strTagLess, "
    ", vbCrLf)

    If anybody used
    around me, I'd shoot 'em.

  • (cs) in reply to tomanyregex
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

  • sweavo (unregistered) in reply to bstorer
    bstorer:
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

    How about "well, first you have to compile the regexp"

  • CATS (unregistered)

    You have no chance to survive make your time. Ha ha ha ha.

  • Pyro (unregistered)

    why bother fixing? using VB is the real WTF anyway :)

  • The peoples hypocrite (unregistered)

    of course this the shorter sequence of the much longer set of functions which included replacing <input type="text" /> and <textarea /> or <input type="text"/> and <textarea>or <INput type="text" /> and <TExtarea /> and so on...</p> </textarea>

  • (cs)

    Though technically the browser probably wouldn't care what came between
    so the regular expression should probably account for any number of anything, assuming there is at least one whitespace character between
    . :-/






  • Christian (unregistered) in reply to cBradley
    cBradley:
    As awesome as regular expressions are, they aren't taught in most Comp Sci programs.

    They're almost certainly taught in 99.999% of courses on compilers. Aren't compiler courses still taught in a majority of CS programs?

  • (cs) in reply to sweavo
    sweavo:
    bstorer:
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

    How about "well, first you have to compile the regexp"

    How about "precompile the regex for superior asymptotic performance?" Or how about "never mind, .NET appears to cache the regex anyway, so you'll still get better asymptotic performance?"

  • Sam (unregistered) in reply to cBradley
    As awesome as regular expressions are, they aren't taught in most Comp Sci programs.

    If a college educational curriculum doesn't cover regular expressions and other finite state machines, it's not a CS curriculum.

  • (cs) in reply to xtremezone
    xtremezone:
    Though technically the browser probably wouldn't care what came between
    so the regular expression should probably account for any number of anything, assuming there is at least one whitespace character between
    . :-/




    Well I think "<br\s*/?>" would probably do it on most sites.

  • Pez (unregistered) in reply to bstorer
    bstorer:
    strTagLess = Replace(strTagLess, "
    ", vbCrLf)

    If anybody used
    around me, I'd shoot 'em.

    If anyone used anything other than
    around me, I'd shoot them...

    Captcha: atari - Old Skool!

  • Sam (unregistered) in reply to sweavo
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex.
    sweavo:
    How about "well, first you have to compile the regexp"
    How about getting the code right first and optimizing later? The regex is more flexible, more readable, and less prone to failure than the original code.

    In addition, until you profile the code, how do you know that the regex solution is slower? First, .NET should only compile the regex once and cache the compiled regex. And, given the simplicity of the regex, it still may be faster to compile and run the regex rather than the 3 contains and 12 replace statements, especially if the string is of a very large size. The regex only needs to scan the string once, versus the 15 times in the initial code.

  • (cs) in reply to sweavo
    sweavo:
    bstorer:
    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

    How about "well, first you have to compile the regexp"

    On a text of non-negligible lenght, 15 operations that have to look through the entire text would give the competing regexp engine ample time to do some compilation.

  • linepro (unregistered)

    All together now:

    "The real wtf is that Mickey is using VB"

  • (cs) in reply to bstorer
    bstorer:
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

    No, no, no. XSLT is much faster.

  • HeavyWave (unregistered)

    Am I the only one who would just use toLower() ? O_o

  • nEUrOO (unregistered)

    Nop, not the only one for the toLower :X What the heck, a regular expression for that!!

  • Tom (unregistered)

    Please. I'll take someone's well-crafted RegEx over a nest of Ifs any day.

    Who writes this crap?

    CAPTCHA: dubya. Well that explains it.

  • (cs)

    I like how easy it is to predict what the comments are going to be about based on the content of the article. I don't even have to read them anymore.

    Anyway, on topic, who the heck graduates with the CS degree without knowing regexps? It's like graduating without understand big-O notation...

  • (cs) in reply to Zecc
    Zecc:
    bstorer:
    tomanyregex:
    The ifs would actually perform faster and use less memory then the regex. And the if approach could have been simplified to evaluate one character at a time. But that doesn't matter. Sure regex make you look really smart, but that doesn't mean its better

    Three Contains and twelve Replace faster than a very simple regex? If that's true, then the designer of VB's regex engine has some explaining to do.

    No, no, no. XSLT is much faster.
    Okay, you're going to hell.

  • Salty (unregistered) in reply to Pyro
    Pyro:
    why bother fixing? using VB is the real WTF anyway :)

    That opinion is so 1990's.

  • Gamen (unregistered) in reply to HeavyWave
    HeavyWave:
    Am I the only one who would just use toLower() ? O_o

    Why not? The code does it 3 times.

    As for a regex that would match most
    tags, /<br[^>]*>/i

  • Geoff (unregistered) in reply to Tukaro
    <\s*br\s*/\s*>
    
  • (cs) in reply to HeavyWave
    HeavyWave:
    Am I the only one who would just use toLower() ? O_o

    toLower would be bad, you'd lose the case of everything else is in the input.

    "This is
    A TesT"

    Should convert to

    "This is A TesT"

    not "this is a test"

  • (cs) in reply to HeavyWave
    Pez:
    bstorer:
    strTagLess = Replace(strTagLess, "
    ", vbCrLf)

    If anybody used
    around me, I'd shoot 'em.

    If anyone used anything other than
    around me, I'd shoot them...

    Captcha: atari - Old Skool!

    XHTML is mostly useless in this day and age. Unless there's a specific need for something in XHTML (hint: there rarely is), it makes more sense to stick with HTML and use
    .

    HeavyWave:
    Am I the only one who would just use toLower() ? O_o
    nEUrOO:
    Nop, not the only one for the toLower :X What the heck, a regular expression for that!!

    Both of you seem to have missed a vital fact: toLower'ing everything only works for LOCATING, which the original examples shows he's well aware of. If you're going to replace, which the example does, you'll end up with a string entirely in lower case - and that's a pretty bad thing.

  • AC (unregistered) in reply to Tukaro

    ... and more: http://xkcd.com/208/

    captcha: gotcha

  • AC (unregistered) in reply to AC
    AC:
    ... and more: http://xkcd.com/208/

    captcha: gotcha

    Meh, that was in reply to

    Tukaro:
    You know, I'm fairly certain that Regular Expressions could cook breakfast for me if I could figure out the right sequence.
  • AC (unregistered)
    Jake Vinson (TFA):

    ,
    ,
    , etc. are all valid HTML
    Are we sure about that?
  • AC (unregistered) in reply to AC
  • (cs) in reply to cBradley

    This is actually true. I never learned them in college. You could probably teach a whole class on them. Or at least there are lots of classes worth.

    I still am not sure how to use the look behind(ahead) feature. Never needed to get that complicated.

    Regex is so important and makes lives sooo much easier. You think they'd have more of the spotlight.

  • Anders (unregistered) in reply to nEUrOO

    Presumably the code needed to preserve case, though. So toLower (or, looking at the code, LCase) wouldn't be an option.

  • (cs) in reply to Pez
    Pez:
    bstorer:
    strTagLess = Replace(strTagLess, "
    ", vbCrLf)

    If anybody used
    around me, I'd shoot 'em.

    If anyone used anything other than
    around me, I'd shoot them...

    Captcha: atari - Old Skool!

    If anyone used anything other than
    around me, I'd shoot them.

  • Anders (unregistered) in reply to Anders
    Anders:
    Presumably the code needed to preserve case, though. So toLower (or, looking at the code, LCase) wouldn't be an option.

    ...teach me to reply before refreshing. :( Also I forgot to quote who I was replying to. I'm not good at this 'internet' thing.

  • Michael (unregistered) in reply to Salty
    Salty:
    Pyro:
    why bother fixing? using VB is the real WTF anyway :)

    That opinion is so 1990's.

    So is VB.

  • (cs) in reply to Christian
    Christian:
    cBradley:
    As awesome as regular expressions are, they aren't taught in most Comp Sci programs.

    They're almost certainly taught in 99.999% of courses on compilers. Aren't compiler courses still taught in a majority of CS programs?

    One of the things I have run into is that, though it may be taught in CS programs it wasn't taught in my program. My degree is in CIS(Computer Information Systems), throwing that information systems in there evidently gave them license to just skip huge sections of my education.

    As an example my asp.net professor asked our class if we had ever had any asp experience before, when the entire class responded in the negative, he assured us that .net was just like asp and then proceeded to never teach anything about either .net or asp, the entire class was devoted to learning what an n-tier architecture was, and labs that couldn't be done because of the schools security policies.

    WTF-U alum class of 2006

  • (cs) in reply to tomanyregex
    tomanyregex:
    Sure regex make you look really smart, but that doesn't mean its better
    Yes it does. Looks are everything.
  • Jon (unregistered) in reply to Welbog
    Welbog:
    Anyway, on topic, who the heck graduates with the CS degree without knowing regexps? It's like graduating without understand big-O notation...

    We never covered RegEx in my CS courses, but covered big-O like crazy. While covering big-O and algorithm analysis has been extremely influential in my programming, I use RegEx much more frequently. (Well, maybe not, I guess everything we do in programming is about algorithm analysis, must be more of a reflex now.) All the RegEx I know I learned on-the-job. I wish we covered RegEx, but at this point I don't think I know any less about it than if we did. Unless it would be reflexive if we did cover it... (still have to look up some RegEx syntax)

  • Anon Fred (unregistered) in reply to bstorer
    bstorer:
    What CS program did you have that didn't include regex? We had to learn the language theory and design our own regex engine.
    I know they're a bit of an outlier, but you can get a CS degree from MIT without taking the compilers class where they go over the theory of regexp's.

    For that matter, you can also get through without learning C or Ruby or PHP or Perl or Python or JavaScript.

    (Most students learned about them on their own time. It's the ones that didn't that you really need to watch out for.)

Leave a comment on “Breaking Broken”

Log In or post as a guest

Replying to comment #:

« Return to Article