Earlier quoted context omitted.
You're misreading the regex. \u200c is a single whitespace character. http://www.fileformat.info/info/unicode/char/200c/index.htm
But that's a weird character to put in a comment line! I don't get how this would happen accidentally.
Stack Overflow Outage Postmortem
281–290 of 335 posts
Re: Stack Overflow Outage Postmortem
#282A few months ago, a Stack Overflow representative asked me if their presence at a dev conference was justified. My positive answer more or less revolved around the importance SO took in the daily life of programmers everywhere. If only she was there to witness the effect of a 34 minute downtime on an open space full of mobile/back/front developers.
Re: Stack Overflow Outage Postmortem
#283Re: Stack Overflow Outage Postmortem
#284"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."
Re: Stack Overflow Outage Postmortem
#285Earlier quoted context omitted.
This regular expression has been replaced with a substring function. God I wish all my bugs were this easy to fix and deploy
i wish people would stop using regular expressions in situations where they can be replaced with a substring function.
> While I can't speak for the original motivation from many moons ago, .Trim() still doesn't trim \u200c. It's useful in most cases, but not the complete strip we need here.
This would have probably been my train of thought (assuming that I consider regex to be a valid solution):
Trim() would have been the correct solution, were it not for that behavior. Substring is therefore the correct solution. Problem is, IndexOf only accepts a char array (not a set of some form, i.e. HashSet). You'd need to write the IndexOfNonWhitespace methods yourself. Use a regex and make sure that it doesn't backtrace, because it's expressive and regex "is designed to solve this type of problem." The real problem/solution here isn't substring, it's finding where to substring.
I consider regex too dangerous to use in any circumstance, but I can certainly see why someone would find it attractive at first.
[1]: https://www.reddit.com/r/programming/comments/4tt6ce/stack_e...
Re: Stack Overflow Outage Postmortem
#286^[\s\u200c]++|[\s\u200c]++$
That should stop any runaway backtracking?
Re: Stack Overflow Outage Postmortem
#287"This regular expression has been replaced with a substring function." This should be the title of a book on software engineering.
I've fixed so many bugs using regex, only to have to fix several bugs later. My current stance is, avoid regex if at all possible. Turns out, many of the things we use regex for is possible without. Often times, .Substring, .IndexOf, and using LINQ over strings is sufficient.
Re: Stack Overflow Outage Postmortem
#288Earlier quoted context omitted.
Yeah, I'm trying to figure out how you even get 20,000 spaces into a Stack Exchange post, and how it would render in your browser.
I can tell you how. A shitty Belkin KVM in certain configurations can allow this to happen. There's a bug which keeps generating chr(32) characters when you activate the keyboard shortcut (scroll lock twice), and try to switch to another machine. It will keep pumping out those spaces on whatever fields was selected at the time, so if you take your time before you switch back, you are going to be in for a lot of fun.…
I've got of course checks in place that warn about trailing spaces and my Git hooks outright refuse a commit with trailing spaces. But it would be nice to catch that at the insert level.
You know, it may be cat who's typing.
Re: Stack Overflow Outage Postmortem
#289Earlier quoted context omitted.
> I mean, if the engine tried matching from the second space, what would be matching the first space? Something has to. Some regex engines provide an API call that puts an implicit `.STAR?` at the beginning of the regex so that the semantics of the match are "match anywhere" as opposed to "match only from the start of the string." (This is in fact the difference between Python's `match` and `search` methods.) Assumin…
For anyone else who wants to time the examples without copying & pasting each line: python3 -m timeit -n 1 -r 3 -s "import re ; haystack = (' ' * 20000) + 'a'" -c "re.match('\s+$', haystack)" 1 loops, best of 3: 467 usec per loop python3 -m timeit -n 1 -r 3 -s "import re ; haystack = (' ' * 20000) + 'a'" -c "re.search('\s+$', haystack)" 1 loops, best of 3: 4.23 sec per loop Options -n how many times to execute statem…
Re: Stack Overflow Outage Postmortem
#290Am sure it was simple but curious to know what the replacement substr code is.