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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:31:41+00:00 2026-05-29T06:31:41+00:00

I’m working with a javascript templating system for a website I’m building and I’m

  • 0

I’m working with a javascript templating system for a website I’m building and I’m having a bit a of problem.

I’m using the following regex to match with sections within my string:

 /(\{\{(#|\^)(.*?)\?\}\}(.*?)\{\{\/(.*?)\?\}\})/

Feeding this a string such as:

 {{#is_user?}} The user is an user {{/user?}}

While stating “user”=true, displays the string. When “is_user” is set to false, the string is not shown. However I’ve found that this allows no room for nesting as such that:

 {{#is_user?}} The user is an user {{#has_picture?}} and has a picture{{/has_picture?}} {{/user?}}

This will result in the following:

The user is an user  {#is_user?}} The user is an user{{/user?}}   

Thus meaning the the match is found between {{#is_user?}} and {{/has_picture?}} as the regex just checks for a match between {{# anystring ?}} and {{/ anystring? }}.

Now my question is if its possible to say that there’s only a match if the two strings between the brackets are equal so that a match is only found when {{#stirngA?}} {{/stringA?}}.

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

    You can make your regex only match the corresponding opening tag by using backreferences.

    E.g.:

    /(\{\{(#|\^)(.*?)\?\}\}(.*?)\{\{\/(\3)\?\}\})/
    

    or without capturing all groups:

    /(?:\{\{(?:#|\^)(.*?)\?\}\}(.*)\{\{\/(?:\1)\?\}\})/
    

    The \3 (or \1) will contain the value of the first (.*?).

    See it on rubular.

    But this might not fully solve your problem of nested matches. Although you could use the result and apply the regex again. Maybe thats enough for your specific case.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from

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.