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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:34:50+00:00 2026-06-18T07:34:50+00:00

I got a little confused about Python raw string. I know that if we

  • 0

I got a little confused about Python raw string. I know that if we use raw string, then it will treat '\' as a normal backslash (ex. r'\n' would be \ and n). However, I was wondering what if I want to match a new line character in raw string. I tried r'\\n', but it didn’t work.

Anybody has some good idea about 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-18T07:34:51+00:00Added an answer on June 18, 2026 at 7:34 am

    In a regular expression, you need to specify that you’re in multiline mode:

    >>> import re
    >>> s = """cat
    ... dog"""
    >>> 
    >>> re.match(r'cat\ndog',s,re.M)
    <_sre.SRE_Match object at 0xcb7c8>
    

    Notice that re translates the \n (raw string) into newline. As you indicated in your comments, you don’t actually need re.M for it to match, but it does help with matching $ and ^ more intuitively:

    >> re.match(r'^cat\ndog',s).group(0)
    'cat\ndog'
    >>> re.match(r'^cat$\ndog',s).group(0)  #doesn't match
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'NoneType' object has no attribute 'group'
    >>> re.match(r'^cat$\ndog',s,re.M).group(0) #matches.
    'cat\ndog'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am little bit confused about Zend authentication session storage system. I will try
i am a little confused about COM threading models. I got a C++ COM
I've got to say I'm a little confused about how to handle request parameter
I'm new in Reporting services and got little confused. in the screen shot you
i got a got a little embedded system that can be controlled via a
I got a little problem, I got a code, that reads all pixels and
I got a little confusing situation here when I use the Context from django.template.
So I m a little confused about how linked list works and how do
I'm a little confused about building an app for the app store and for
I'm a little confused about the distinction between mutable and immutable objects. I tried

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.