简体   繁体   English

如何对重叠的字符集进行模式匹配? (使用正则表达式和grep)

[英]How to pattern-match an overlapping set of characters? (using regex and grep)

say we have 说我们有

1: ..FAF..FAF..
2: ..FAF.......
3: ..FAFAF.....

I need to pattern-match a triplet that occurs at least 2 times in a string, for example line 1&3 (the dots are placed to make it readable, they are actually characters [AZ] ). 我需要对一个字符串中至少出现两次的三元组进行模式匹配,例如1&3行(这些点被放置为易于阅读,它们实际上是字符[AZ] )。

I have only the solution for line 1 我只有第1行的解决方案

egrep '([A-Z]{3,}).*\1'

PS this is a simplified version of my text file PS,这是我的文本文件的简化版本

PPS it has to be with grep PPS必须与grep一起使用

UPDATE UPDATE

I think I found the answer: 我想我找到了答案:

egrep '([A-Z]{3}).*\1|([A-Z])([A-Z])\1\2\1'

here is my trial pattern 这是我的试用模式

(\b[A-Z]([A-Z]{2,})\2\b|\b([A-Z]{3,})\b.*\3)  

Demo 演示

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

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