I need a regular expression that matches a word. However the expression must be valid until the word is completed.
Example开发者_运维技巧: Using the word "stackoverflow"
all parts of words must be valid "s" "st" "sta" "stac" "stack" "stacko" .... so on until the complete word.
if there is "stt" is invalid.
Also have to consider that the words "stackoverflowx" or "xstackoverflow" are invalid
Thank you all.
This is a problem that sounds it would be much better solved with
var input = "st"; // or "sta", or ...
bool isValid = "stackoverflow".StartsWith(input);
See it in action.
Is there some reason you have to use a regular expression?
Who says Stackoverflow is a word? Is it in the dictionary? :)
Why is xstackoverflow or stt not a word? Who's dictionary are you using?
Are you just wanting to detect unpronouncable phonemes?
If you are wanting to compare a dictionary you will probably do to read up on prefix trees (tries) as a method of storing dictionaries.
I would also advise against using regex to match partial patterns, I've had difficulty getting relatively simple ones to match, never mind entire dictionaries.
精彩评论