I have a string "abcdefg". I'd like to match any substring that is equivalent to removing characters at the end. So in addition to matching "abcdefg", the strings "abc", "a", and "abcd" should all match.
Using a|ab|abc|abcd|abcde|abcdef|abcdefg
will work, but it is essentially just a list of strings.
Is there a more space efficient way to do this?
Additionally, I can't use lookaheads/lookbehinds as they are not supported in Go.
CodePudding user response:
I'd code up a check by hand. Regexes aren't really a good tool for this. But you know, if you insist...
a(b(c(d(e(f(g)?)?)?)?)?)?