- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
You know, I'm fairly certain that Regular Expressions could cook breakfast for me if I could figure out the right sequence.
Admin
considering that
is just as legal.. oh well.
Admin
Admin
separated by any number of spaces.
Admin
He's lucky the tag isn't <line break goes here>
Admin
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.
Admin
Oops...
Admin
Admin
It could, but the eggs would always look like they are scrambled.
Admin
Admin
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
Admin
If anybody used
around me, I'd shoot 'em.
Admin
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.
Admin
How about "well, first you have to compile the regexp"
Admin
You have no chance to survive make your time. Ha ha ha ha.
Admin
why bother fixing? using VB is the real WTF anyway :)
Admin
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>
Admin
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
. :-/
Admin
They're almost certainly taught in 99.999% of courses on compilers. Aren't compiler courses still taught in a majority of CS programs?
Admin
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?"
Admin
If a college educational curriculum doesn't cover regular expressions and other finite state machines, it's not a CS curriculum.
Admin
Well I think "<br\s*/?>" would probably do it on most sites.
Admin
If anyone used anything other than
around me, I'd shoot them...
Captcha: atari - Old Skool!
Admin
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.
Admin
Admin
All together now:
"The real wtf is that Mickey is using VB"
Admin
Admin
Am I the only one who would just use toLower() ? O_o
Admin
Nop, not the only one for the toLower :X What the heck, a regular expression for that!!
Admin
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.
Admin
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...
Admin
Admin
That opinion is so 1990's.
Admin
Why not? The code does it 3 times.
As for a regex that would match most
tags, /<br[^>]*>/i
Admin
Admin
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"
Admin
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
.
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.
Admin
... and more: http://xkcd.com/208/
captcha: gotcha
Admin
Admin
Admin
Yus: http://validator.w3.org/check?uri=http%3A%2F%2Fpaste.css-standards.org%2F27771%2Fview&charset=%28detect+automatically%29&doctype=Inline&group=0
Admin
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.
Admin
Presumably the code needed to preserve case, though. So toLower (or, looking at the code, LCase) wouldn't be an option.
Admin
If anyone used anything other than
around me, I'd shoot them.
Admin
...teach me to reply before refreshing. :( Also I forgot to quote who I was replying to. I'm not good at this 'internet' thing.
Admin
Admin
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
Admin
Admin
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)
Admin
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.)