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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:21:54+00:00 2026-06-09T07:21:54+00:00

I ran in to an unexpected difficulty with regular expression matching in python: As

  • 0

I ran in to an unexpected difficulty with regular expression matching in python:
As expected:

>>> re.match("r", "r").group() #returns...
"r"

However:

>>>re.match("r", "$r").group()
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'

Does anybody know why the dollar sign causes trouble when it’s in the string to be matched, and how I can fix 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-09T07:21:56+00:00Added an answer on June 9, 2026 at 7:21 am

    Look at the difference between re.match and re.search

    >>> re.match("r", "$r")    # no match since re.match is equivalent to '^r'
    >>> re.search("r", "$r")   # match
    <_sre.SRE_Match object at 0x10047d3d8>
    

    re.match searches from the BEGINNING of the string, so “r” does not match “$r” because “$r” does not start with ‘r’.

    re.search scans through the string, so it is not dependent on the start of the string.

    As a general form, you should do matching this way:

    match=re.search(pattern, string)
    if match
       # you have a match -- get the groups...
    else:
       # no match -- deal with that...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up from Perl regular expression to match an IP address .
While creating a map of String to partial functions I ran into unexpected behavior.
I ran across an unexpected problem with the following code. List<string> items = new
I ran into unexpected behavior with a function I wrote to compute the average
I ran into an unexpected code optimization recently, and wanted to check whether my
I've been playing around with Backbone.js and ran into something a bit unexpected. It
I recently endeavoured to learn about multiple threading, and ran into the following unexpected
I just ran into some unexpected behavior with DateTime.UtcNow while doing some unit tests.
I ran into what was to me an unexpected result when testing a simple
I recently ran into a pretty unexpected (to me) behavior of JPA (provided by

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.