Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The pattern detects if a number N is not prime by searching for A and B such that N = A*B. The (11+?) searches for A bigger than 1, and the repetition of this group (the \1+ part) repeats A as much as possible, eventually B times. If an exact match isn't possible, it backtracks and advances A. If no such A and B exist, A will keep increasing until it becomes bigger than N, and then the match fails.

An interesting pattern that wasn't immediately obvious, but a very inefficient way to detect primes :)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: