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 8276621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:25:32+00:00 2026-06-08T08:25:32+00:00

I came across this problem as I was working on the Python Challenge .

  • 0

I came across this problem as I was working on the Python Challenge. Number 10 to be exact. I decided to try and solve it using regexes – pulling out the repeating sequences, counting their length, and building the next item in the sequence off of that.

So the regex I developed was: '(\d)\1*'

It worked well on the online regex tester, but when using it in my script it didn’t perform the same:

regex = re.compile('(\d)\1*')
text = '111122223333'
re.findall(regex, text)

> ['1', '1', '1', '1', '2', '2', '2',...]

And so on and so forth. So I learn about raw type in the re module for Python. Which is my first question: can someone please explain what exactly this does? The doc described it as reducing the need to escape backslashes, but it doesn’t appear that it’s required for simpler regexes such as \d+ and I don’t understand why.

So I change my regex to r'(\d)\1*' and now try and use findall() to make a list of the sequences. And I get

> ['1', '2', '3']

Very confused again. I still don’t understand this. Help please?

I decided to do this to get around this:

[m.group() for m in regex.finditer(text)]
> ['1111', '2222', '3333']

And get what I’ve been looking for. Then, based off of this thread, I try doing findall() adding a group to the whole regex -> r'((\d)\2*)'.
I end up getting:

> [('1111', '1'), ('2222', '2'), ('3333', '3')]

At this point I’m all kinds of confused. I know that this result has something to do with multiple groups, but I’m just not sure.

Also, this is my first time posting so I apologize if my etiquette isn’t correct. Please feel free to correct me on that as well. Thanks!

  • 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-06-08T08:25:33+00:00Added an answer on June 8, 2026 at 8:25 am

    Since this is the challenge I won’t give you a complete answer. You are on the right track however.

    The finditer method returns MatchObject instances. You want to look at the .group() method on these and read the documentation carefully. Think about what the difference is between .group(0) and .group(1) there; plain .group() is the same as .group(0).

    As for the \d escape character; because that particular escape combination has no meaning as a python string escape character, Python ignores it and leaves it as a backslash and letter d. It would indeed be better to use the r'' literal string format, as it would prevent nasty surprises when you do want to use a regular expression character set that also happens to be an escape sequence python does recognize. See the python documentation on string literals for more information.

    Your .findall() with the r'((\d)\2*)' expression returns 2 elements per match as you have 2 groups in your pattern; the outer, whole group matching (\d)\2* and the inner group matching \d. From the .findall() documentation:

    If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.

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

Sidebar

Related Questions

I'm using GAE with python and I came across this problem, I'm trying to
I'm working through 'Dive Into Python' on Google App Engine and came across this
I was working in php java bridge and came across this problem. The below
I came across this problem, I have a number of type long which represents
I have came across this problem when using pointer to pointer to a char:
I came across this problem when I want to check what I input is
I came across this problem when trying to decode json into an array ,
i came across this problem, my code in the viewWillAppear method is not executed
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
I was configuring syntax highlighting for my blog when I came across this problem.

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.