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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:53:48+00:00 2026-06-08T13:53:48+00:00

I have a a previously matched pattern such as: <a href=somelink here something> Now

  • 0

I have a a previously matched pattern such as:

<a href="somelink here something">

Now I wish to extract only the value of a specific attribute(s) in the tag such but this may be anything an occur anywhere in the tag.

regex_pattern=re.compile('href=\"(.*?)\"') 

Now I can use the above to match the attribute and the value part but I need to extract only the (.*?) part. (Value)

I can ofcourse strip href=" and " later but I’m sure I can use regex properly to extract only the required part.

In simple words I want to match

abcdef=\"______________________\"

in the pattern but want only the

____________________

Part

How do I do this?

  • 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-08T13:53:50+00:00Added an answer on June 8, 2026 at 1:53 pm

    Take a look at the .group() method on regular expression MatchObject results.

    Your regular expression has an explicit group match group (the part in () parethesis), and the .group() method gives you direct access to the string that was matched within that group. MatchObject are returned by several re functions and methods, including the .search() and .finditer() functions.

    Demonstration:

    >>> import re
    >>> example = '<a href="somelink here something">'
    >>> regex_pattern=re.compile('href=\"(.*?)\"') 
    >>> regex_pattern.search(example)
    <_sre.SRE_Match object at 0x1098a2b70>
    >>> regex_pattern.search(example).group(1)
    'somelink here something'
    

    From the Regular Expression syntax documentation on the (...) parenthesis syntax:

    Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. To match the literals ‘(‘ or ‘)’, use \( or \), or enclose them inside a character class: [(] [)].

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

Sidebar

Related Questions

I asked this question earlier: mod_rewrite: match only if no previous rules have matched?
Very specific question but we have some good Ada people here so I would
I have previously written user interfaces using .NET and Windows Forms. I'm about to
I have previously read Spolsky's article on character-encoding, as well as this from dive
I have previously been told that I should always use Randomize() before I use
Suppose that we have previously instantiated three objects A, B, C from class D
I'm developing a graph control in WPF. I have previously developed it using GDI
I'm looking to implement a REST client in PHP, and have previously been using
I previously have been reading NMEA data from a GPS via a serial port
I believe this question might have been previously attempted in 2006 on a different

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.