Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:47:52+00:00 2026-05-24T20:47:52+00:00

I want to find all consecutive, repeated character blocks in a string. For example,

  • 0

I want to find all consecutive, repeated character blocks in a string. For example, consider the following:

s = r'http://www.google.com/search=ooo-jjj'

What I want to find this: www, ooo and jjj.

I tried to do it like this:

m = re.search(r'(\w)\1\1', s)

But it doesn’t seem to work as I expect. Any ideas?

Also, how can I do it in Bash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:47:53+00:00Added an answer on May 24, 2026 at 8:47 pm

    ((\w)\2{2,}) matches 3 or more consecutive characters:

    In [71]: import re
    In [72]: s = r'http://www.google.com/search=ooo-jjjj'
    In [73]: re.findall(r'((\w)\2{2,})', s)
    Out[73]: [('www', 'w'), ('ooo', 'o'), ('jjjj', 'j')]
    
    In [78]: [match[0] for match in re.findall(r'((\w)\2{2,})', s)]
    Out[78]: ['www', 'ooo', 'jjjj']
    

    (\w) matches any alphanumeric character.

    ((\w)\2) matches any alphanumeric character followed by the same character, since \2 matches the contents of group number 2.
    Since I nested the parentheses, group number 2 refers to the character matched by \w.

    Then putting it all together,
    ((\w)\2{2,}) matches any alphanumeric character, followed by the same character repeated 2 or more additional times.

    In total, that means the regex require the character to be repeated 3 or more times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find all img tags in a string of text and put
I want to find all instances in a table where a string field cannot
I want to find all occurences of BBB in a string and substitute them
I want to find all the consecutive numbers in a an ordered int[8] of
I want to find all the consecutive numbers in a an ordered int[8] of
I want to find all records which maps to object XYZ with following conditions
I want to find all the transitive closure loops in my graph having following
For example I want to find all elements that have computed style position: fixed;
I want to find all if statements and for statements which are not followed
I want to find all items in one collection that do not match another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.