user5373025
user5373025

Reputation:

Match consecutive duplicate characters, ignoring case

So I know (.)\1 is the format for finding consecutive characters with a regular expression, but I've noticed it is case sensitive, so it won't pick up "sS" or "hH" on a text field or string.

How would I change this, and also how would I implement it using python 3.5 with the re.findall method?

Upvotes: 1

Views: 718

Answers (2)

eumiro
eumiro

Reputation: 212895

Add re.IGNORECASE:

re.findall(r'(.)\1', 'aA', re.IGNORECASE)

to match strings like aA.

Docs: https://docs.python.org/2/library/re.html#re.IGNORECASE

Upvotes: 4

pguetschow
pguetschow

Reputation: 5337

You should ignore the case like this:

re.IGNORECASE

https://docs.python.org/2/library/re.html

Upvotes: 1

Related Questions