My favorite regex of all time
81–90 of 117 posts
Re: My favorite regex of all time
#82My favorite regex is the following, /^1?$|^(11+?)\1+$/ Which finds prime numbers. Although, I can't for the life of me think of a reason for using it. http://stackoverflow.com/questions/3296050/how-does-this-reg...
I do dislike people calling that expression a "regex", because it isn't: regular expressions cannot contain backreferences, and must be computable in linear time, whereas primality tests are polynomial.
Re: My favorite regex of all time
#83Earlier quoted context omitted.
I do dislike people calling that expression a "regex", because it isn't: regular expressions cannot contain backreferences, and must be computable in linear time, whereas primality tests are polynomial.
I'm not a big fan of your explanation. To be more precise, true "regular expressions" are computationally equivalent to deterministic finite automata, which indeed can test an n-character string in O(n) time.
Re: My favorite regex of all time
#84Earlier quoted context omitted.
It's not an ASCII v EBCDIC thing, its an ASCII vs Unicode thing.
It's not just Unicode either. I just mentioned EBCDIC because that particular regex has bit me before when I was translating perl scripts from Linux to zOS USS. Take a look at the code page for EBCDIC, you'll see quickly why it's a massive pain to sort through regexes like that.
Re: My favorite regex of all time
#85Earlier quoted context omitted.
I do dislike people calling that expression a "regex", because it isn't: regular expressions cannot contain backreferences, and must be computable in linear time, whereas primality tests are polynomial.
I'm not a big fan of your explanation. To be more precise, true "regular expressions" are computationally equivalent to deterministic finite automata, which indeed can test an n-character string in O(n) time.
Re: My favorite regex of all time
#86Earlier quoted context omitted.
I don't understand why this is "completely unreadable". What else could this have been besides match the character range from space to tilde?
Most people would have to check an ASCII table to know what that range is, though.
Re: My favorite regex of all time
#87As someone who makes much of his living rehabilitating old perl scripts, please, if you must use such things, use them like this: [ -~] #match only printable characters It takes 5 seconds longer and with regexes, just knowing what the damn thing is trying to do is half the battle. When you use a regex, use a comment. Its the civil thing to do.
Yea, anytime I use a regex that isn't immediately obvious I put it in a function called get_ . Unfortunately people that write overly complicated and error prone regexes usually don't choose to document them.
Re: My favorite regex of all time
#88This works for ASCII only, use unicode character classes instead.
That only matters if you need to process Unicode. See my comments [1] [2] [3] for why Unicode / internationalization should be avoided. [1] http://news.ycombinator.com/item?id=4369323 [2] http://news.ycombinator.com/item?id=4541039 [3] http://news.ycombinator.com/item?id=4775440
Even if you focus on u.s., you will have problems. If you're doing a CRM, even u.s. users will put in foreign names from time to time. If you're building a CMS, users may want to put in a quotation in french, or will simply use copy&paste from Word, which replaces "-" with "—"...
I honestly have a hard time finding a u.s. centric startup which could afford to ignore unicode. The support requests, the fires caused by errors, and the disclaimer that you'd have to put on the registration page, would cost much more than simply learning how to code the f'n utf.
Building MVP is good practice in Lean. Saying "I'm bootstrapping hence I don't have the time to learn the programming tools" is just ignorance and incompetence. It's not like Unicode gives you extra work, it just requires you to learn a few basic concepts. If you try to build a site which doesn't support Unicode, you'll have to put a lots of safeguards everywhere to cover up for your incompetence.
Re: My favorite regex of all time
#89Are people seriously still deliberately using ASCII-reliant code?
Every time I've had to deal with Unicode and internationalization, it's been a problem. For example, a few years ago I grabbed a source tarball from somewhere, I forget what or where. It had the author's name in a comment, which included an O with dots over it. That was the only non-ASCII character in the source code. No matter what I did, both Eclipse and command-line javac refused to compile the source. Finally I w…
Re: My favorite regex of all time
#90My favorite regex is the following, /^1?$|^(11+?)\1+$/ Which finds prime numbers. Although, I can't for the life of me think of a reason for using it. http://stackoverflow.com/questions/3296050/how-does-this-reg...
I do dislike people calling that expression a "regex", because it isn't: regular expressions cannot contain backreferences, and must be computable in linear time, whereas primality tests are polynomial.
So I'd argue that code is RegEx.
I guess it's just a matter of perspective though.