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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:53:25+00:00 2026-06-03T08:53:25+00:00

With PHP I’m trying to get my regular expression to match both template references

  • 0

With PHP I’m trying to get my regular expression to match both template references below. The problem is, it also grabs the </ul> from the first block of text. When I remove the /s flag that it only catches the second reference. What I’m a doing wrong?

/{{\%USERS}}(.*)?{{\%\/USERS}}/s 

Here is my string.

<ul class="users">
{{%USERS}}
<li>{%}</li>
{{%/USERS}}
</ul>

{{%USERS}} hello?!{{%/USERS}}

Why is my expression catching too much or too little?

  • 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-03T08:53:26+00:00Added an answer on June 3, 2026 at 8:53 am

    Why is my expression catching too much or too little?

    1. Its catching too much because the quantifiers are greedy by default (see Li-aung Yip answer +1 for that)

    2. If you remove the modifier s it matches only the second occurrence, because that modifier makes the . also match newline characters, so without it, it’s not possible to match the first part, because there are newlines in between.

    See the non greedy answer

    {{\%USERS}}(.*?){{\%\/USERS}}
    

    here on Regexr, a good place to test regular expressions.

    Btw. I removed the ? after the capturing group, its not needed, since * matches also the empty string, so no need to make it additionally optional.

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

Sidebar

Related Questions

php file.php & How to get PID of the background process in file.php ?
PHP 5.2.15 I am trying to replace {date[F]} with the date function. I have
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
PHP Redirect with Post Data Hi, I am a newbie PHP programmer and trying
PHP 5 introduces the magic method __get() and __set(). From my understanding it is
PHP currently will not log errors produced from the command line. I have: log_errors
PHP provides a mechanism to register a shutdown function: register_shutdown_function('shutdown_func'); The problem is that
I'm trying to create an if statement in PHP that prevents a single post
php isn't really my thing but I would need to get the votes and
php gives the ability to send arrays from the _GET. example: test.php?var1=abc&arr[0]=1&arr[3]=test will output:

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.