Question

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.

Was it helpful?

Solution

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?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top