Hacker News new | ask | show | jobs
by memorable 1439 days ago
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.
1 comments

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.