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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:21:20+00:00 2026-06-14T02:21:20+00:00

What would be the shortest solution to capture a string between two markers? For

  • 0

What would be the shortest solution to capture a string between two markers?

For example, let’s imagine I have

blahblahblah —foobar– blahblahblah

And I want to capture “foobar”.

I can capture the string “—foobar–” quite easily with a regex.

But since I don’t want the prefix “—” and suffix “–“, I need many steps to clean up the result :

  1. get position of prefix “—” (since we already captured the bloc, we know the position is 0)
  2. get length of “—” (for the sake of the example, let’s assume we don’t know the size of the limiter, it can be “—” or “–” or “-“)
  3. get position of suffix “–“, starting at position position_prefix+prefix_length
  4. substring between position_prefix+prefix_length and position_suffix

Of course I can build myself such a function to do that if I need it, but is there already a built-in solution for that?

Something like captureWithoutDelimiters(group_regex, prefix_regex, suffix_regex) ?

  • 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-14T02:21:21+00:00Added an answer on June 14, 2026 at 2:21 am

    How about:

    [\w\s]+-+(\w+)-+[\w\s]+
    

    Then you can just print out what’s caught by the first capture group.

    Explanation:

    [\w\s]+     // Match at lest 1 letter or white space character
    -+          // Followed by at least 1 marker character
    (\w+)       // Capture the word inside the markers
    -+          // Followed by more marker characters
    [\w\s]+     // Followed by at lest 1 letter/white space character
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have two lists of points: List<Point2D> a; List<Point2D> b; What would
I need a function to find the shortest distance between two line segments. A
I am looking for shortest solution for the following problem: I would like to
I have a string of numbers that i would like to make shorter for
For a Data Structures project, I must find the shortest path between two words
what would be the shortest way to write this? if(strpos($haystack, $needle)!==false){ $len = strpos($haystack,
Would be possible to extend this kind of layout so that I can have
Would it be possible to put install THG on a shared drive and let
I want the shortest possible way of representing an integer in a URL. For
How do you draw the curve representing the shortest distance between 2 points on

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.