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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:43:09+00:00 2026-05-26T17:43:09+00:00

I am try to understand this code: Var1 = re.compile(rnothing is (\d+)).search i am

  • 0

I am try to understand this code:

Var1 = re.compile(r"nothing is (\d+)").search

i am want to see what is the affect of the r notation right after the ( sign on the \d.
i know that \d mean to find decimal numbers (the \ mean that d has a special meaning), is that mean that without the r notation i would use \ ? if so why ?
i know that at the bash shell it is enough to put just one \ .

i have read here: http://docs.python.org/library/re.html#raw-string-notation

but i’m can’t understand how it affects the snippets code above.
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-05-26T17:43:10+00:00Added an answer on May 26, 2026 at 5:43 pm

    It’s a raw string literal. It changes backslashes to be treated literally (almost, see below). This is particularly useful when writing regular expressions as they often contain backslashes and if you use ordinary string literal you may have to escape the backslashes, making the regular expression harder to read.

    Without the r your code would look like this:

    f = re.compile("nothing is (\\d+)").search
    

    Note that not escaping the backslashes also works in this case because '\d' is not a valid escape sequence:

    f = re.compile("nothing is (\d+)").search
    

    However, relying on this behaviour may result in errors unless you (and everyone who has to maintain your code) can memorize the list of allowable escape sequences.


    The rules for raw string literals are:

    When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. For example, the string literal r"\n" consists of two characters: a backslash and a lowercase 'n'. String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the string, not as a line continuation.

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

Sidebar

Related Questions

I try to understand lexical-scoping. In lexical-scoping, I have this code, C like syntax:
I try to understand how Protovis works, and I stumbled upon code like this:
I am not able to understand why this code doesn't compile: class A {
I'm new to win32 API programming and I try to understand source code of
I do not understand this code snippet : function ms(){ var plc=unescape('. unescape( '\x43\x43\x43\x43\n.............\xEF'.
I can't understand this... Cannot get this code to run and I've no idea
So the short version, what I don't understand is this line of code: (new
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
Try to understand WPF. This is my test classes: public partial class MainWindow :
I'm trying to understand this code and I can't :( $time = date('Y-m-d', strtotime('-30

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.