正则表达式包含一个单词的所有部分
我需要一个与单词匹配的正则表达式。然而,在单词完成之前,表达式必须有效。
示例:使用单词“stackoverflow”,
单词的所有部分都必须有效 “s” “英石” “斯塔” “斯塔克” “堆” “stacko”......依此类推,直到完整的单词。
如果有“stt”则无效。
还必须考虑到“stackoverflowx”或“xstackoverflow”这些词是无效的
谢谢大家。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题听起来可以通过
查看实际操作得到更好的解决。
有什么原因必须使用正则表达式吗?
This is a problem that sounds it would be much better solved with
See it in action.
Is there some reason you have to use a regular expression?
谁说 Stackoverflow 是一个词?字典里有吗? :)
为什么 xstackoverflow 或 stt 不是一个词?你用谁的字典?
您只是想检测无法发音的音素吗?
如果您想比较字典,您可能会阅读前缀树(尝试)作为存储字典的方法。
我还建议不要使用正则表达式来匹配部分模式,我很难获得相对简单的模式来匹配,更不用说整个字典了。
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.