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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:18:01+00:00 2026-06-17T14:18:01+00:00

I have this code and its not working import re mystring = This is

  • 0

I have this code and its not working

import re
mystring = "This is my test the string to match the stuff"    
p = re.compile(" the ")

Now I want to able to put the first match found in var1 and second match in var2

  • 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-17T14:18:02+00:00Added an answer on June 17, 2026 at 2:18 pm

    You mean something like this?

    In [3]: import re
    
    In [4]: strs= "This is my test the string to match the stuff"
    
    In [5]: p = re.compile(" the ")
    
    In [6]: re.findall(p,strs)
    Out[6]: [' the ', ' the ']
    
    In [7]: var1,var2=re.findall(p,strs)
    
    In [8]: var1,var2
    Out[8]: (' the ', ' the ')
    

    In case the number of matches returned are more than 2, then you’ve slice the list first.

    var1,var2=[' the ', ' the ',' the '][:2]
    

    On python 3.x you can take the advantage of the * to grab the rest of the elements in a list:

    In [2]: var1,var2,*extras=[' the ', ' the ','foo','bar']
    
    In [3]: var1
    Out[3]: ' the '
    
    In [4]: var2
    Out[4]: ' the '
    
    In [5]: extras             #rest of the elements are stored in extras
    Out[5]: ['foo', 'bar']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code and its working but i want it to return dailyTotals
i have tried this code to redirect a php page.but it s not working
sorry about input mistakes, english its not my mother lang. I have this code
I have this code for splitting input list into its halves. It seems to
I have this code: STRB R2, [R0,R1] and its opcode is 42 54 I'm
I have this code in my index.php. In Mozilla its ok. But in Ie
its a little bit hard to understand. in the header.php i have this code:
I have an implementation of lazyDataModel following this tutorial http://uaihebert.com/?p=1120 My code its a
I have been working on this problem for close to 4 days now. I
I have the following piece of code. I do not understand why its not

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.