开发者

Regular expression all parts a word

开发者 https://www.devze.com 2023-04-03 14:40 出处:网络
I need a regular expression that matches a word. However the expression must be valid until the word is completed.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号