Hacker News new | ask | show | jobs
by iforgotpassword 1436 days ago
That's not that wrong though.

What does it do for queries like "all male English names" or "comfortable temperature range"?

1 comments

For "comfortable temperature range", it generates:

  (\d+\.?\d*)\s?-\s?(\d+\.?\d*)
And for "all male English names", it generates:

  [A-Z][a-z]+
The first one might be good, but the latter seems rather unsophisticated.
All male English names is just a list. It doesn’t follow a grammar. Its regex would be akin to

    (John|Jane|Alice|Bob)
and so on. It’s not a case for regex. In fact, I’ve found success in replacing regex with regular string operators (length, contains substring, doesn’t contain substring, starts with a capital letter, …) of the language at hand, then do final regex passes for whatever is left at the end. It’s infinitely more readable and debuggable. I’ve grown to avoid regex when possible.