JavaScript
-
Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:
-
No, you are not the first and you will not be the last. To the best of my knowledge since release only 4 people have thought "wow, that's well designed".
Reality is an illusion caused by a lack of alcohol "Nagy, you have won the internets." - Keith Barrow
Nagy Vilmos wrote:
To the best of my knowledge since release only 4 people have thought "wow, that's well designed".
... and all four of them have previously tried to parse html using regexes.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
For me it still applies if you remove the "JavaScript" from there.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
Really? What language? For me the syntax of
string.replace(/[wte]/g, string)
was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.
-
Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:
-
Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:
-
Really? What language? For me the syntax of
string.replace(/[wte]/g, string)
was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.
-
Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:
Yeah, regex literals are strange in JavaScript, but to be fair I don't know of any other language with regex literals. JavaScript does also have a sinsible way to create a regex variable:
var reggy = new RegExp("someregex", "options");
-
Really? What language? For me the syntax of
string.replace(/[wte]/g, string)
was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.
MehGerbil wrote:
Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.
Coming from a Perl background I found it surprisingly clear ;)
-
Yeah, regex literals are strange in JavaScript, but to be fair I don't know of any other language with regex literals. JavaScript does also have a sinsible way to create a regex variable:
var reggy = new RegExp("someregex", "options");
AspDotNetDev wrote:
JavaScript does also have a sinsible way to create a regex variable:
var reggy = new RegExp("someregex", "options");
As for JavaScript, just keep in mind that the literal form
/regex/
is compiled once (when the script is loaded), whereas the explicit constructor call
new RegExp(pattern, options)
is compiled every time it's passed. see JavaScript RegExp Object... Regex is more enjoyable if you (can!) use(=write) it when needed. I have never regretted to have learned. (syntax isn't a big challenge any more)
-
MehGerbil wrote:
Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.
Coming from a Perl background I found it surprisingly clear ;)
PERL? Don't get me started...
I may not last forever but the mess I leave behind certainly will.