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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:21:03+00:00 2026-06-17T15:21:03+00:00

When the parenthesis were used in the below program output is [‘www.google.com’] . import

  • 0

When the parenthesis were used in the below program output is
['www.google.com'].

import re
teststring = "href=\"www.google.com\""
m=re.findall('href="(.*?)"',teststring)
print m;

If parenthesis is removed in findall function output is ['href="www.google.com"'].

import re
teststring = "href=\"www.google.com\""
m=re.findall('href=".*?"',teststring)
print m;

Would be helpful if someone explained how it works.

  • 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-17T15:21:05+00:00Added an answer on June 17, 2026 at 3:21 pm

    The re.findall() documentation is quite clear on the difference:

    Return all non-overlapping matches of pattern in string, as a list of strings. […] 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.

    So .findall() returns a list containing one of three types of values, depending on the number of groups in the pattern:

    • 0 capturing groups in the pattern (no (...) parenthesis): the whole matched string ('href="www.google.com"' in your second example).
    • 1 capturing group in the pattern: return the captured group ('www.google.com' in your first example).
    • more than 1 capturing group in the pattern: return a tuple of all matched groups.

    Use non-capturing groups ((?:...)) if you don’t want that behaviour, or add groups if you want more information. For example, adding a group around the href= part would result in a list of tuples with two elements each:

    >>> re.findall('(href=)"(.*?)"', teststring)
    [('href=', 'www.google.com')]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below from http://www.scalaclass.com/book/export/html/1 to do matrix dot product. I can't understand the
I need to understand bash if expressions. Sure, I've used Google. I know that
What do parenthesis do in Java other than type casting. I've seen them used
The SQL statement below used to work a few years ago, now it doesn't
I've created this simple program to auto-generate sequence of frames to be used in
What are the parenthesis doing in [s addChild: [restartAction() node]]; or what is that
I have seen Javascript code that uses parenthesis immediately after a function's closing curly
How Do You Turn On Parenthesis Matching in Visual Studio 2005? This is relevant
Lua has a really nice no-parenthesis call syntax that coupled with function closures allow
How to make Visual Studio to insert parenthesis automatically after method names in C#?

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.