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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:23:48+00:00 2026-05-23T16:23:48+00:00

I would usually do something like this using a string libray. But I wonder

  • 0

I would usually do something like this using a string libray. But I wonder if it can be done using a regex.

I want to do the following: Given a search string:

Seattle is awesome

I want to find all substrings of it in a given sentence. So applying a regex to the following sentence

Seattle Seattle is awesome is awesome awesome is Seattle

Should give me

Seattle, Seattle is awesome, is awesome, awesome, is, Seattle

One constraint that might be helpful is that the sentence will always have only the words present in the search string and whitespaces in between.

Note If there’s a match, it should be the longest possible string. So like in the above example the matches shouldn’t be single words rather longest possible substrings. Order among words also needs to be maintained. That’s why

awesome is Seattle

in the sentence above gives us

awesome, is and Seattle

I am not sure if something like this can be done with a regex though, since it is greedy. Would appreciate any insight into this!
I’m familiar with both C# and Java and could use either of their regex libraries.

  • 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-23T16:23:48+00:00Added an answer on May 23, 2026 at 4:23 pm

    There is no good way to express such a pattern directly with a regex.

    You’ll need to list all allowed combinations:

    Seattle is awesome|Seattle is|Seattle|is awesome|is|awesome
    

    or more succinctly:

    Seattle( is( awesome)?)?|is( awesome)?|awesome
    

    You can programmatically transform your input string to this format.

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

Sidebar

Related Questions

I often find I want to write code something like this in C#, but
I usually perform things like this in C++, but I'm using python to write
When performing many inserts into a database I would usually have code like this:
Has anyone done something like this? How? I'm just starting a project that will
I want to do something like this: I want the user to provide a
In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
So right now if I have something like this: //div[@class='artist']/p[x]/text() x can either be
I wonder how long it would usually take for: Professional Average Beginner to setup
How would I usually represent this business logic in a graph? A is true
I would like to read a little more about the + that is usually

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.