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 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

I would like to have a RegEx that matches several of the same character
Possible Duplicate: Regex question mark I am trying to figure out how to parse
Question Is it possible to stop a Message Driven Bean (programmatically), so that it
THE QUESTION Is it possible to run one tab from a different Activity or
Thanks to the help with my previous homework question Regex to match tags like
I have a handy-dandy regex provided from a previous SO question : $regex =
Possible Duplicate: Regex to match 4 groups of letters/numbers, separated by hyphens Apologies in
Possible Duplicate: replace all occurrences in a string I found this question/answer: Use JavaScript
I have a question! I'm not sure if this is possible, but... I have
This question relates to character class subtraction in regular expression (regex). I refer to

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.