GSandro_Strongs
GSandro_Strongs

Reputation: 911

how can I search letter pairs matches with regex?

I'm using regex to find occurrences in a string python, for example: "cw cx", "cw cx av", "cw cx dr wt" or "cw cx qw hv eb". The match can be 2, 3, 4 or 5 pairs. I'm thinking something like this "([a-zA-Z]{2}) ([a-zA-Z]{2})" Please help me

Upvotes: 2

Views: 160

Answers (2)

Dump Cake
Dump Cake

Reputation: 300

You are almost there. Try this: ([a-zA-Z]{2} ){1,4}[a-zA-Z]{2}

Upvotes: 1

anubhava
anubhava

Reputation: 785631

You can use this regex:

\b[a-zA-Z]{2}(?: [a-zA-Z]{2}){1,4}\b

RegEx Demo

Upvotes: 1

Related Questions