Regex: How to match sequence of SAME characters?

user2492270

I am trying to match "any consecutive chains of SAME character that is NOT .(period) "

Lets say I have

line = '....xooo......'

If I do this,

match in re.findall(r'[^\.]{2,}', line)

match returns "xooo".

Instead, I only want "ooo," which is a sequence of SAME character..

How do I do this?

thefourtheye
line = '....xooo......aaaa...'
import re
print [whole for whole, _ in re.findall("(([^.])\\2+)", line)]

Output

['ooo', 'aaaa']

([^.]) matches anything but . and it is captured as a group. \\2 refers to the inner captured group which is the character matched by ([^.]) and + means atleast once. So, it matches ooo

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to match specific characters only?

来自分类Dev

Elegant way to use regex to match order-indifferent groups of characters (in a substring) while limiting how may times a given character can appear?

来自分类Dev

How to dynamically create regex to use in .match Javascript?

来自分类Dev

How to get regex match on my scenario

来自分类Dev

Java Regex: How to Match URL Path?

来自分类Dev

Regex - Escape escape characters

来自分类Dev

Replacing characters in a regex

来自分类Dev

Wrong RegEx match in Dart

来自分类Dev

Jquery Value match Regex

来自分类Dev

Regex multiple match substring

来自分类Dev

Search/Match regex in Python

来自分类Dev

为什么[regex] match()和-match不同?

来自分类Dev

为什么[regex] match()和-match不同?

来自分类Dev

Regex to match and limit character classes

来自分类Dev

Shortest match in regex from end

来自分类Dev

std :: regex_match与字符éèà

来自分类Dev

C ++ regex_match行为

来自分类Dev

Codeigniter regex_match与比较

来自分类Dev

how to create sequence

来自分类Dev

REGEX获得“ any_characters((number,number))”

来自分类Dev

Check regex for letters numbers and underscore characters

来自分类Dev

Adding several special characters to existing regex

来自分类Dev

查找Regex.Match失败的地方

来自分类Dev

C ++无法使regex_match正常工作

来自分类Dev

PHP: Trying to understand subpattern regex match

来自分类Dev

Javascript regex match()返回匹配的部分(子集)

来自分类Dev

Using regex in Scala to group and pattern match

来自分类Dev

Regex to match the first half of a UK postcode

来自分类Dev

C ++ boost :: regex_match奇怪的行为