简体   繁体   English

Emacs正则表达式可搜索包含多个单词的行

[英]Emacs regexp to search lines containing multiple occurrences of a word

I am trying to understand whether regexp search can be used to search for lines that contain a certain word multiple times. 我试图了解正则表达式搜索是否可以用于多次搜索包含某个单词的行。

For example, I would like to find the line below because it contain twice the word Cable 例如,我想找到下面的行,因为它包含单词Cable的两倍

<Connection Action="New" ID="277766368412" From="Cable:25425374" FromPosition="84" To="Cable:25389991" ToPosition="12"></Connection>

What should my regexp look like? 我的正则表达式应该是什么样?

Thanks 谢谢

Joe

You should clarify the question, because the way it is, the obvious "Cable.*Cable" works. 您应该澄清这个问题,因为它的方式是显而易见的"Cable.*Cable"

Maybe you want references, they work as well: "\\\\(Cable\\\\).*\\\\1" . 也许您想要引用,它们也可以正常工作: "\\\\(Cable\\\\).*\\\\1"

Just in case you didn't know before re-builder is a nice tool. 以防万一您在re-builder之前是个不错的工具。 Just paste your string into a buffer and experiment with re-builder . 只需将字符串粘贴到缓冲区中,然后尝试使用re-builder

Something like \\<\\(.*\\)\\>.*\\1 should work, although you might want to have a more restrictive pattern inside the capturing parenteses; \\<\\(.*\\)\\>.*\\1应该可以工作,尽管您可能希望在捕获的括号内有一个更严格的模式。 the current one doesn't attempt to restrict the matched pattern to a single "word" but you could change the dot to eg [A-Za-z] if that's a suitable "word" definition for you. 当前的代码不会尝试将匹配的模式限制为单个“单词”,但是如果这对您来说是合适的“单词”定义,则可以将点更改为例如[A-Za-z]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM