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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:21:30+00:00 2026-06-16T05:21:30+00:00

I have this string: >>> s = ‘Evolution Recruitment (Agency) (London, UK)’ I want

  • 0

I have this string:

>>> s = 'Evolution Recruitment (Agency) (London, UK)'

I want to get this part:

London, UK

Keep in mind that for the real case I’m working on the first brackets (agency) are not necessarily in the string.

I tried this:

>>> import re
>>> re.findall("\((.*?)\)$", s)
['Agency) (London, UK']

If I was able to let the regex read from right to left instead of left to right this solution should work.

Is that possible? If not, is there another way to get the part London, UK?

  • 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-16T05:21:32+00:00Added an answer on June 16, 2026 at 5:21 am
    In [8]: re.search(r".*[(](.*)[)]", s).groups()
    Out[8]: ('London, UK',)
    

    It just uses a greedy .* match to get to the last set of parentheses.

    Alternatively, you could find all matching parentheses, and just use the last pair:

    In [14]: re.findall(r'\(.*?\)', s)[-1]
    Out[14]: '(London, UK)'
    

    The regex approach is quite flexible. However, if you know the input’s well-formed and you just want the text inside the last set of parentheses:

    In [11]: s[s.rfind('(')+1:s.rfind(')')]
    Out[11]: 'London, UK'
    

    This scans the string right-to-left, so could potentially be fairly efficient (I have profiled anything, so that’s just a speculation).

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

Sidebar

Related Questions

I have this String : Charle,Mike,Stephan,Andre,Jenny, I just want to get : Charle Mike
I have this string that I get back from Adobe Presenter 7. It's called
I have this string: image/fewe that I want to replace with something else, but
I have this string s that is formatted in this way. I want to
I have this string: http://localhost/whatever/index.php/something/cms-abc.html?___SID=U I want to get the cms-abc from that string.
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this String String criteria=ESS.(BVA4+BVA5)+(-(DIESE.(BVM5+BVM6))); I want to put validations on it. It
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
I have this string: 123-456-7 I need to get this string: 1234567 How I
We have this string: according to posts #4,#5 and #6 the word... I want

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.