当字符串出现两次时匹配正则表达式 [英] Regex to match when a string is present twice

查看:55
本文介绍了当字符串出现两次时匹配正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 RegEx 表达式很糟糕,我只是不经常使用它们,以至于我无法记住使用之间的语法.

I am horrible at RegEx expressions and I just don't use them often enough for me to remember the syntax between uses.

我正在使用 grepWin 搜索我的文件.我需要进行搜索以返回具有给定字符串两次的文件.

I am using grepWin to search my files. I need to do a search that will return the files that have a given string twice.

因此,例如,如果我在搜索单词how",那么文件 1 将不匹配:

So, for example, if I was searching on the word "how", then file one would not match:

你好
你今天好吗?

Hello
how are you today?

但文件二会:

你好
你今天好吗?

Hello
how are you today?

我很好,你好吗?

有人知道如何制作一个与之匹配的正则表达式吗?

Any one know how to make a RegEx that will match that?

推荐答案

类似这样的事情(取决于语言和您的具体任务)

something like this (depends on language and your specific task)

\(how.*){2}\

根据@CodeJockey

according to @CodeJockey

\^(([^h]|h[^o]|ho[^w])*how([^h]|h[^o]|ho[^w])*){2,2}$\

(变得更复杂)@CodeJockey:感谢评论

(it become more complicated) @CodeJockey: Thanks for comments

这篇关于当字符串出现两次时匹配正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆