正则表达式-单词的匹配缩写 [英] Regex - Matching Abbreviations of a Word
本文介绍了正则表达式-单词的匹配缩写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在考虑提供以下正则表达式作为对这个问题,但我似乎无法写出我正在寻找的正则表达式:
I was thinking in providing the following regex as an answer to this question, but I can't seem to write the regular expression I was looking for:
w?o?r?d?p?r?e?s?s?
这应该与单词 wordpress $ c $的有序缩写匹配c>,但它也完全不能匹配。
This should match a ordered abbreviation of the word wordpress
, but it can also match nothing at all.
如何修改上面的正则表达式,使其按顺序匹配至少4个字符?像这样:
How can I modify the above regex in order for it to match at least 4 chars in order? Like:
- 单词
- wrdp
- press
- wordp
- wpress
- wordpress
- word
- wrdp
- press
- wordp
- wpress
- wordpress
我想知道什么是最好的方法... =)
I'd like to know what is the best way to do this... =)
推荐答案
您可以使用前瞻性断言:
You could use a lookahead assertion:
^(?=.{4})w?o?r?d?p?r?e?s?s?$
这篇关于正则表达式-单词的匹配缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文