4 ms·
I feel like Charlie Kelly from IASIP reading this regex. "1. Starts out with 1, then there is other stuff...." https://youtu.be/AFDU_R6ShmI?t=74 https://youtu.
by ahmed_ds 5y ago
I feel like Charlie Kelly from IASIP reading this regex. "1. Starts out with 1, then there is other stuff...."
https://youtu.be/AFDU_R6ShmI?t=74 https://youtu.be/AFDU_R6ShmI?t=74
- Dylan16807 5y agoHuh, looking at some regex explaining sites, they don't seem to do a good job of simplifying. Which is a shame because it's really easy to simplify away most of this regex. / does nothing ^ and $ only exist to make it do the whole string | is just saying "or", and only the part to the right really matters. And the ? doesn't do anything meaningful. Throw all that out and all you have is (11+)\1+ It's still a mash of symbols, but it's much simpler. And changing it to (cc+)\1+ would probably help naive readability too.
- aghilmort 5y agomy fave regex explainer gives this, idk that it adds much? https://regexper.com/#%2F%5E1%3F%24%7C%5E%2811%2B%3F%29%5C1%2B%24%2F https://regexper.com/#%2F%5E1%3F%24%7C%5E%2811%2B%3F%29%5C1%...
- Dylan16807 5y agoThat's the best I've seen so far, at least. Much better than a bunch of bullet points of various indentation.
- mordechai9000 5y agoThe question mark isn't meaningless - it changes the matching behavior of + from greedy to non-greedy. The non-greedy version will try to match shorter strings first. This should be more efficient, because non-primes will fail sooner. Most numbers will fail a lot sooner.
- Dylan16807 5y agoIt takes just as long on primes, so the overall runtime will be very similar. So sure it's an optimization but it's not one to care about when you're trying to understand it.