- 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
I don't see the frist problem ;-)
Admin
[^:<>|@] matches "asdf:<>|@"; the first match is "a". Where you thinking about ^[^:<>|@]$?
Admin
He probably meant ^[^:<>|@]*$
Also, fun how putting it in a sentence with punctuation changes the meaning of the regex.
Admin
Given how hard people evidently find it to write the negation of even a simple regex, maybe this code isn't such a WTF after all.
Admin
Is a negative regex an irregex or an aregex?
Admin
How about negregex?
Admin
null
Admin
I'd suggest negex
Admin
The worst thing like this I've seen is people making classes such as "ProperRegex" or "AwesomeBestlyPracticingRegex" that extend regex and override methods to throw exceptions when there's a none match. You then see oodles of what should be if statements replaced with exception handling.
Admin
exregex?
Admin
never knew the joke until now !!!
People kept it from me. They would come up to me. A socially induced aphasia due to conflict, later self-healed.
Tumors effectively receive the spectrum. I had no clue what that meant. I had no clue of the name until now. That's all!
I read Hawking thoroughly, really tried to understand what he was getting at. The Fluid Mechanic theories, much more cooler!!!
They say they need a delivery system. There it is. Just ping the hubble. Aliens want us to tune it out.
They tried to mensa my father with me forever. I think it was due to draft dodging?
He had one answer when they did it to him.
MY genes!
ME !!!
<what> hitler ???
just borneo the bastard!
Admin
it's cool!!! my genes !!! God Save the Queen!
Admin
Don't you need to escape some of those characters? e.g. backslash and pipe?
Admin
first:
http://bit.ly/2GrWhpY
Admin
http://bit.ly/2p9EHi6
Admin
Maybe unregex? What about notregrex? Or xeger?
Admin
In many cases you can't use a regex to specifically not match another regex. Or, you want to allow anything that matches regex A but not regex B, in which case making 2 regexes (regices?) is legit.
The inheritance is a WTF indeed though.
Admin
You can if your regex library supports negative lookahead, in which case
/^(?!.*[:<>|@])/
has a similar effect to/^[^:<>|@]*$/
.Admin
Ah, but you see, that's just it. Once you subscribe to the doctrine of exceptionism, no error at all should ever be handled by an if statement. The only thing if is good enough for is simple things like if (value < 5) ... else if (value > 8) ... else ... . Even if (value != 0) ... is dubious; that should really be handled with a ZeroValueException or something similar.
Admin
I actually quite like the idea of "inverting" a regular expression by negating the result of the match function. It seems like it could be less error-prone (writing a regular expression to match a specific string or pattern is quite easy but writing a regular expression to not match something is difficult at least once you get past single characters).
Admin
http://bit.ly/2FTOgMG
Admin
A non-regex! It has shuffled off its mortal parentheses! It has become a Kleene-star in the sky! IT IS AN EX-REGEX!
Admin
OK, call me crazy, but if you have a regular expression, but it is in code, and you are checking it, and you want to make sure to exclude things, can't you just use the wonderful ! operator and write an If with the second regex? if( regex1.match && !regex2.match)...
Admin
Sure, you could - if you were one of those peasants who has a measly little boolean returned from your regex matching function. It's a bit harder to do when your regex matching function returns null on a match, or a specific string on failure.