For writing a parser I need to be able to identify keywords which can be abbreviated,
for example
MY-KEYWORD
should at least be MY-KEY but can also be any abbreviation longer than this, here specifically MY-KEYW, MY-KEYWO, MY-KEYWOR or the full MY-KEYWORD.
For the life of me, no regex I tried so far (and that were many …) matches exact substrings of something with a minimum length 🙁
TIA !
Alex
>Solution :
Match the prefix and then optional characters after it to finish the full keyword.
\bMY-KEY(?:W(?:O(?:RD?)?)?\b
All the groups are needed to ensure that no optional letters are skipped. If you wrote MY-KEYW?O?R?D it would match MY-KEYD.