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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:24:22+00:00 2026-06-10T16:24:22+00:00

Looking for a python regex pattern. Seems like it has to exist, but it

  • 0

Looking for a python regex pattern. Seems like it has to exist, but it has me stumped.

If I need to find an address, and the strings I am searching can be of the form

address_is_after_123
 - or -
123_address_is_before

Note, there could be more than two permutations, but I’m hoping a solution for two permutations could be extended to more.

I could simply create multiple regexes, but I’d ideally like a single regex. The best I’ve got is:

m = re.match("(?:address_is_after_(\d+)|(\d+)_address_is_before)",text)

This works, but the I have to test whether m.group(1) or m.group(2) has the value. Is there a way to write the regex so that if it matches I can grab the address without additional processing?

  • 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-10T16:24:24+00:00Added an answer on June 10, 2026 at 4:24 pm

    You could do it with lookarounds, provided that the length of the lookbehind ("address_is_after_") is constant:

    >>> m = re.search(r"(?<=address_is_after_)\d+|\d+(?=_address_is_before)",text)
    >>> m.group(0)
    '123'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a regex to search my python program to find all lines
I am looking for a python SOAP 1.2 client but it seems that it
I'm new to regex, but looking through a string to find whether or not
I'm looking for a python socket server framework - not to handle http, but
I am having some trouble searching for a multiline pattern using regex. Here is
I'm writing a python regex that looks through a text document for quoted strings
How do I make a python regex like (.*) such that, given a (b)
I'm looking for a regex to match hyphenated words in Python. The closest I've
I have a file which has text like this: #1#14#ADEADE#CAH0F#0#0..... I need to create
I'm a newbie in Python looking to build a screen scraper in Scraperwiki but

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.