A regex to satisfy the grammar police (there vs. their vs they're)

-2

We've all been burned by the grammar police on the internet. What we need is a regex that can be used in place of "there", "their", and "they're". This would shift burden of grammar parsing from the writer to the reader (a sort of "client-side" grammar, if we you will). So, here's what I have to start with:

the([re]|[ir]|[y're]).

...but I'm positive there's room for optimization.

What's the shortest regex that could be used in place of any variation or the aforementioned homohpones?

mdwhatcott

Posted 2016-10-20T17:32:29.210

Reputation: 131

7Your regex isn't correct. It matches ther, thee, thei, they and the'. Can't dig up a link right now, but look up "character classes". (Followed by any character if the . is supposed to be part of the regex, but that seems like a formatting mistake.) – Martin Ender – 2016-10-20T17:33:51.217

Bit off-topic with no objective winning criterion, but could actually be a cool challenge. – Magic Octopus Urn – 2016-10-20T17:36:26.540

@carusocomputing I believe it's a golfing tips question which is definitely on topic.

– Martin Ender – 2016-10-20T17:36:49.480

1Knot ay gud eye deal too mi. Gust rite it rite. – Geobits – 2016-10-20T17:46:17.290

As worded the correct answer to the question is .*, but I'm sure that's not what you intended to ask. Also, spelling is not grammar. You should be complaining about the orthography police, not the grammar police. – Peter Taylor – 2016-10-20T20:59:17.273

Answers

17

There isn't a lot of room for optimisation here. This seems to be optimal:

the(y're|re|ir)

The only alternative I can think of avoids the duplication of re but ends up at the same byte count (and it's potentially worse in flavours where meta characters need to be escaped to work):

the((y')?re|ir)

Martin Ender

Posted 2016-10-20T17:32:29.210

Reputation: 184 808