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

  • Home
  • SEARCH
  • 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 262827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:33:01+00:00 2026-05-11T22:33:01+00:00

Question: Is is possible, with regex, to match a word that contains the same

  • 0

Question:
Is is possible, with regex, to match a word that contains the same character in different positions?

Condition:
All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don’t know what is it.

Examples:
using lowercase 6char words I’d like to match words where the 3rd and the 4th chars are the same.

parrot <- match for double r
follia <- match for double l 
carrot <- match for double r
mattia <- match for double t
rettoo <- match for double t
melone <- doesn't match

I can’t use the quantifier [\d]{2} because it match any succession of two chars, and what if I say the 2nd and the 4th position instead of 3rd and 4th?

Is it possible to do what I want with regex? If yes, how can I do that?

EDIT:
Ask asked in the comments, I’m using python

  • 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-11T22:33:01+00:00Added an answer on May 11, 2026 at 10:33 pm

    You can use a backreference to do this:

    (.)\1
    

    This will match consecutive occurrences of any character.


    Edit   Here’s some Python example:

    import re
    
    regexp = re.compile(r"(.)\1")
    data = ["parrot","follia","carrot","mattia","rettoo","melone"]
    
    for str in data:
        match = re.search(regexp, str)
        if match:
            print str, "<- match for double", match.group(1)
        else:
            print str, "<- doesn't match"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question So I've recently came up with some new possible projects that would have
Question: Is it possible to construct a web page that has a script to
Here is my question, Would it be possible, knowing that classic asp support server-side
This question is about App domains and Sessions. Is it possible to have IIS
In the context of this question link text is possible from a Controller that
Over in this question, Scott writes that it is possible to get the current
Thanks to the help with my previous homework question Regex to match tags like
I know that I can use regex to match substrings in a string, but
I have a string that I want to parse using regex. It has the
It's quite possible a question like this has been asked before, but I can't

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.