I would like a regular expression that, starting from the beginning of the text, matches the word. If an exact word is entered, it matches, but will also match a certain minimum number of matching characters , provided that any additional characters also match .
For example, if I try to match "San Francisco", but I am ready to accept the first five characters so that they can be uniquely identified in the domain:
- Match: San Francisco
- Match: San F
- Match: San Fra
- Match: San Francisco Blah Blah.
- Crash: Boston
- Crash: San Diego
- Error: San Fransisko
- Crash: San Franco
This almost works, but doesn't match the last two correctly:
^San Fr?a?n?c?i?s?c?o?
I use .NET regular expressions, but a solution in any language will do.
source share