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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:00:06+00:00 2026-05-19T09:00:06+00:00

I am studying about regex, i figured out some about matching one or more

  • 0

I am studying about regex, i figured out some about matching one or more character, but i have a case, but don’t know how to solve this..

For example i have:

$data = "bla bla -start- blu blu blu -end- bla bla";
$pattern = "/\-start\-[\w]\-end\- /";
preg_match($pattern, $data, $matches);
print_r($matches);

i intend to take anything between ‘-start-‘ and ‘-end-‘, so i expect to get
‘ blu blu blu ‘.
any suggestion ?

  • 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-19T09:00:06+00:00Added an answer on May 19, 2026 at 9:00 am

    \w represents only word characters, and you need to also allow for spaces. Assuming you really want to allow anything in between -start- and -end- you can use . which matches any character.

    Hyphens need not be escaped unless enclosed in a character pattern (between square brackets [ and ]), so you can replace \- with just -.

    Just like using a single \w represents matching any single word character, . represents matching any single character, so you need to add some more information in. Following either of these with + would indicate matching at least one character, or with a * would indicate zero or more characters. Assuming you want at least one character, your expression should be okay like this:

    $pattern = "/-start-(.+)-end- /";
    

    Supposing you might encounter an expression like: -start- foo -end- -end- and you want to terminate on the first -end- (the content to extract is foo), then you need to operate in a non-greedy way. PHP’s regex is greedy by default, to turn this off, you follow the + (or a *) with a ?, like this:

    $pattern = "/-start-(.+?)-end- /";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While studying about JMX, I have seen one of the important feature of it
I'm studying about windows and DLL stuffs and I have some question about it.
I am studying patterns and anti-patterns. I have a clear idea about patterns, but
I have recently started studying about threads. I thought of starting from the beginning
I have been studying DDD in-depth on my own time; reading everything about it
I am currently studying recursion in school, and I have trouble thinking about methods
I started studying POSIX timers, so I started also doing some exercises, but I
Hi I am studying Software Engineering, and I have to do a case study
I have been studying as much as I can about the Module Pattern suggested
I am studying for a final and have a few questions about RMI and

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.