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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:28:50+00:00 2026-06-07T06:28:50+00:00

How can I get text within a specific text? Like, if I have a

  • 0

How can I get text within a specific text?
Like, if I have a text like this:

'lololol \r asdfasdf r\ gfhfgr'

How can I get it to return ‘asdfasdf’. Basically, get the text between the bits '\r' and 'r\'?

  • 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-07T06:28:51+00:00Added an answer on June 7, 2026 at 6:28 am

    Another re solution,

    import re
    
    s = r'lololol \r asdfasdf r\ gfhfgr'
    pattern = re.compile('\\\\r (.*?) r\\\\')
    
    print pattern.findall(s)
    

    results in ['asdfasdf']

    Edit:

    Well, dude, that’s what you said you wanted in your example. If you prefer, you are welcome to use

    pattern = re.compile('\\\\r(.*?)r\\\\')
    

    which will instead give you [' asdfasdf '].

    ‘All the slashes’ are needed because of the way Python and re parse strings; a slash is used as an escape character for digraphs like \n (newline character). So to denote a slash, you have to use the \\ digraph. Try print('\\') to see this.

    You then have to double it, because re parses the string again against its own set of digraphs (\d for digits, \s for whitespace, etc). So if you enter '\\\\', Python understand this to be a string composed of two slashes, \\, which it passes to re, which parses it and thinks you are looking for a single \ character.

    Sometimes you can get away without doing this; if you have a string like '\m', where the trailing char does not result in a valid digraph, the result is actually the two-character string \m (try print('\m')). \r is kind of funky; Python recognizes it as a carriage-return digraph, but re does not use \r as a digraph, so giving Python ‘\r’ or ‘\\r’ both result in re looking for the literal string ‘\r’. I prefer the double-double-slash, as this means you don’t have to remember two separate definitions of what is or isn’t a legal digraph! On the other hand, both Python and re recognize \’ as a single-quote digraph (print('\'') prints a ' character) – so both slashes have to be fully double-escaped or you’ll get a “Hey, where’s the rest of the string??” error (‘string not terminated’).

    The other alternative is to enter raw strings (r'abc'); this tells Python not to parse digraphs in the string, but re will still do so, so your pattern has to look like

    pattern = re.compile(r'\\r(.*?)r\\')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have been fiddling with this for hours. I can not get my text
I have a piece of code (below) that can get the text of an
How can I get the text in this markup? <div itemprop=description> <p>Testing article....</p> <div
How can I get the text value from an elements's child? Say I have
How can i get section cell text on custom cell button click. is this
I have a multi-line text view that can get quite large. When the user
While I can get a list of pages within a specific category using 'categorymembers',
I use something like this to get the text from a shape inside PowerPoint:
My question is, how can I get text from header in javascript? So if
How can I get the text value of a segment in a UISegmentedControl?

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.