[英]Regex: match at least 3 characters in a string in specific order
How to search within a given string so that every 3 (or more) character ordered coincidence is captured? 如何在给定的字符串中进行搜索,以便捕获每3个(或更多个) 有序重合的字符? I am using it for applying some conditional restrictions in an HTML search input... My best try so far:
我正在使用它在HTML搜索输入中应用一些条件限制...到目前为止我最好的尝试:
/[deleted]{3,}/g
I need " del ", " ele ", " let ", " ete " or " ted " to be captured... But also " dele ", " eted " or even the full " deleted ". 我需要“ 删除 ”,“ 俄勒 ”,“ 让 ”,“ETE”或“ 泰德 ”被捕获。但是也“DELE”,“eted”,甚至是完整的“ 删除 ”。 The preceding regex does the trick, but the problem now is the order of the characters, because it also captures strings like " ltd " or " eded ", which are not in order with the word and should not.
前面的正则表达式可以解决问题,但现在的问题是字符的顺序,因为它还捕获了像“ ltd ”或“ eded ”这样的字符串,这些字符串与单词不一致 ,不应该。
Any help? 有帮助吗?
Thanks in advance. 提前致谢。
Ok, I finally have found a solution that takes into account all of the restrictions. 好的,我终于找到了一个考虑所有限制的解决方案。 It was a matter of misunderstanding on my part .
这是我的误解问题 。 Sorry.
抱歉。 But thanks for all the replies and comments anyway:
但是感谢所有的回复和评论:
Before posting the question, I started with the PHP solution as (I thought) @Tushar suggested in his first comment: 在发布问题之前,我开始使用PHP解决方案(我想)@Tushar在他的第一条评论中建议:
strpos('deleted', $inputString) !== false
But as it did not work as expected, I went for regex. 但由于它没有按预期工作,我去了正则表达式。 The problem is what I really tested before the question was:
问题是在问题出现之前我真正测试过的:
strpos($inputString, 'deleted') !== false
I exchanged the ' haystack ' and the ' needle ', resulting in unwanted results, so I ended up asking here in stackoverflow... Summing up, the solution from @Tushar is absolutely correct. 我交换了' haystack '和' needle ',导致了不必要的结果,所以我最后在stackoverflow中询问...总结一下,来自@Tushar的解决方案是完全正确的。 Credits to him.
给他的信用。 Thanks mate.
谢了哥们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.