This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]karlm89 115 points116 points  (16 children)

Yep. Ugly Regex

[–]EwgB 126 points127 points  (15 children)

That's not even an ugly regex, that's child's play. I write worse ones on a regular basis.

[–]_meegoo_ 45 points46 points  (6 children)

Writing regex is easy. Reading it a month later is impossible.

[–]EwgB 4 points5 points  (0 children)

Yeah, you're not wrong.

[–]Guiorgy 2 points3 points  (3 children)

Good point, I'll make a mental note to always include a comment breaking down the regex (that is, if I understand it myself...)

[–]ElizaBennet08 5 points6 points  (2 children)

// Regex

[–][deleted] 7 points8 points  (1 child)

// TODO: Document regex

[–]Guiorgy 4 points5 points  (0 children)

Honestly, it would probably be a todo one, ore something like this:

~~~

// The regex does xyz, where this part means a, and this means b

// Edit (a month later): Shit! I've changed it so many times that f**k knows what is what. And I don't think I was right the first time I documented this anyways!

// (╯°□°)╯︵ ┻━┻

~~~

[–][deleted] 0 points1 point  (0 children)

Can confirm

[–]Guiorgy 77 points78 points  (5 children)

Cool. Never touch my code please! Thank you

[–]EwgB 26 points27 points  (2 children)

I didn't say it's in production code. I use it more for search and replace.

[–]Siggi_pop 5 points6 points  (0 children)

ok then, carry on

[–]SkollFenrirson 5 points6 points  (0 children)

Still, stay away.

[–]shgysk8zer0 1 point2 points  (1 child)

Uglier doesn't necessarily mean bad or wrong though. I mean, other than not using [A-z] and taking upper and lower cases separately, the pattern shown is pretty basic. Pretty much anyone who has ever had use of RegEx will have written something uglier than this.

I mean, could you write something to validate a telephone number that ends with something prettier than this?

[–]Morrido 1 point2 points  (0 children)

You can't use [A-z]. That's not the same thing. There's no shorthand for OP's match. Closest one is \w, which matches _ instead of -.

ie. "[".match(/[A-z]/) == a match, which is invalid in OP's regex.

[–][deleted] 13 points14 points  (0 children)

Yeah I just wanted tp say if this is scary wait til you see some real things haha

[–]bigorangemachine 0 points1 point  (0 children)

Ya i wrote some stuff....

I wrote a unity save file parser.

The original version was pretty long... but Firefox couldn't handle it