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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:59:30+00:00 2026-05-21T06:59:30+00:00

I am having a problem with Regex (yes, again, one day I have to

  • 0

I am having a problem with Regex (yes, again, one day I have to sit and read about it).
Here is the code I’m using;

$string = "[if-protectDelete-{0}-][data]name[/data] can be deleted[/elseif][elseif-{1}-][data]name[/data] can't be deleted[/elseif][elseif-{2}-]No data[/elseif][/endif]";

if (preg_match_all("#\[elseif-\{(.+)\}-\](.+?)\[/elseif\]#", $string, $matches)) {
                        dumper($matches[0]);
                    }

$matches[0] output is;

array(1) {
      [0]=>
      string(75) "[elseif-{1}-]PHP REGEX can't be deleted[/elseif][elseif-{2}-]No data[/elseif]"
}

I can get the part right for if, but elseif… It is totally different scenario I guess.
Shouldn’t it out put like this? ;

array {
[0] => "[elseif-{1}-]PHP REGEX can't be deleted[/elseif]",
[1] => "[elseif-{2}-]No data[/elseif]"
}

I will be glad if anyone could help me out with my problem.

  • 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-21T06:59:31+00:00Added an answer on May 21, 2026 at 6:59 am

    Just add ?

    your : \[elseif-\{(.+)\}-\](.+?)\[/elseif\]
    right: \[elseif-\{(.+?)\}-\](.+?)\[/elseif\]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem in replacing chars in string using python's 3 regex. I
having another short regex problem. Basically I have a string like such: cn=WSG-AP-LO-COMMON-SITE-APPS,ou=ZFD,ou=SVC,ou=IGH I'm
I am having a problem extracting a substring from a string using regex. For
I am having problem to split string in java. it gives java.util.regex.Pattern.error . String
I'm having problem with datagrid view. I have attached an image with the code
I'm having a problem getting my RegEx to work with my Ruby script. Here
I'm pretty new on grails, I'm having a problem in matches validation using regex.
I'm having a problem using the Boost library in Dev C++, specifically the regex
Ok so I am having trouble solving a problem with having a Regex using
Having a slight regex problem. I wrote to following code to check if a

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.