Hacker News new | past | comments | ask | show | jobs | submit login

For "6. A man, a plan", I thought it was impossible to match palindromes with regex, am I wrong?



It gives you hints below the score, for 6 it's:

  You're allowed to cheat a little, since this one is technically impossible.
No idea how you cheat...

EDIT, SPOILERS: I get 170 with ^(.?)(.)(.).?\3\2\1$


176 with ^(.)(.).*\2\1$


  ^(.)[^p].*\1$           # 177, "cheat a little"


You're pretty much correct. True regular expressions don't have the expressive power to decide whether arbitrary-length strings are or aren't palindromes.

That said, 'regular expressions', as used in most programming languages, have extensions that extend the expressive power. One such extension is the matched group & backreference, used in other commentor's answers.

From a theoretic stance, these aren't really 'regular expressions', but that's what we call them in practice.




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

Search: