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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:35:00+00:00 2026-05-15T20:35:00+00:00

2 Regex question How can I match a word or 2 words in a

  • 0

2 Regex question

How can I match a word or 2 words in a subpattern ()?

How can i match a word or 2 words that’s either followed by a specific word like “with” OR the end of the string $

I tried

(\w+\W*\w*\b)(\W*\bwith\b|$)

but it’s definitely not working

edit:
I’m thinking of matching both “go to mall” and “go to”, in a way that i can group “go to” in python.

  • 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-05-15T20:35:00+00:00Added an answer on May 15, 2026 at 8:35 pm

    Perhaps something like this?

    >>> import re
    >>> r = re.compile(r'(\w+(\W+\w+)?)(\W+with\b|\Z)')
    >>> r.search('bar baz baf bag').group(1)
    'baf bag'
    >>> r.search('bar baz baf with bag').group(1)
    'baz baf'
    >>> r.search('bar baz baf without bag').group(1)
    'without bag'
    >>> r.search('bar with bag').group(1)
    'bar'
    >>> r.search('bar with baz baf with bag').group(1)
    'bar'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: Is is possible, with regex, to match a word that contains the same
Just a quick regex question...hopefully I have a string that looks something like this:
I know that I can use regex to match substrings in a string, but
A regex answers a yes or no question - does the string match the
Thanks to the help with my previous homework question Regex to match tags like
I need a regex to match a word that starts with #. I wrote
In reference to my question Regex expression to match whole word with special characters
Simple regex question. I have a string on the following format: this is a
This is a really basic regex question but since I can't seem to figure
Quick regex question (since i am horrible at it) I have a field that

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.