[英]Regex: Ignore matches starting with a specific char
I have the following RegEx: 我有以下正则表达式:
(.+?)\1+
It is used for recognizing repeated sequences in a string. 它用于识别字符串中的重复序列。 But the matches may not consist of only digits or points and also they may not start with a point or end with a digit.
但是,比赛可能不只由数字或点组成,也可能不是以点开头或以数字结尾。 I tried using:
我尝试使用:
^[^\.](.+?)\1+$[\d]
But this solution is not working. 但是此解决方案不起作用。 For example it is not recognizing
4F.4F.4F.
例如,它无法识别
4F.4F.4F.
Edit: 编辑:
I found the solution by combining all the ideas of the answers. 我通过结合答案的所有想法找到了解决方案。 It is:
它是:
(?!\\.)(.+?)\\1+(?<=\\D)
This id what you need. 您需要的这个ID。
result = re.findall(r"^(?!\.)(\w+\.)(?!.\d)\1+", subject)
DEMO http://regex101.com/r/pA5bL0 演示 http://regex101.com/r/pA5bL0
I'd use Lookaheads: 我会用Lookaheads:
(?!\.)(.+)(?<![0-9])\1+
Demo: http://regex101.com/r/iQ0aT6 演示: http : //regex101.com/r/iQ0aT6
这符合您的规格:
result = re.findall(r"([^.].*?\D)\1", subject, re.DOTALL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.