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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:53:17+00:00 2026-05-25T15:53:17+00:00

I have a problem with a javascript template parser where valid matches for the

  • 0

I have a problem with a javascript template parser where valid matches for the regex are not being matched. I have tested the regular expression and it was working previously which makes me think it’s something with my code.

The issue is with the codeblock regex. It is not matching 2 out of the 4 valid patterns in the template.

I have the following function:

function LoadParsedRowTemplate(rowData, type) {

    var template = Templates[type];
    var replacement = null;
    var result = null;
    var expression;

    var refbinder = /@\{[\S\s]*?}@/g;
    var databinder = /#\{[\S\s]*?}#/g
    var codeblock = /%\{[\S\s]*?}%/g;
    var ctlbinder = /\$\{[\S\s]*?}\$/g;

    try {

        while ((result = refbinder.exec(template)) != null) {
            replacement = "rowData." + result[0].substring(2, result[0].length - 2);
            template = template.replace(result[0], replacement);
        }

        while ((result = databinder.exec(template)) != null) {
            replacement = eval("rowData." + result[0].substring(2, result[0].length - 2));
            template = template.replace(result[0], replacement);
        }

        while ((result = codeblock.exec(template)) != null) {
            expression = result[0].substring(2, result[0].length - 2)
            replacement = eval(expression);
            template = template.replace(result[0], replacement);
        }

        while ((result = ctlbinder.exec(template)) != null) {
            replacement = eval("$.fn.ScreenSetup." + result[0].substring(2, result[0].length - 2));
            template = template.replace(result[0], replacement);
        }
    }
    catch (err) {
        $.error("Error: Data template Binding Error: " + err.toString());
    }

    return template;

}

With the following template:

    <script id="ReturnLineDataRowTemplate" type="text/template">
        <tr>
            <td><input type="checkbox" /></td>
            <td>
                <input type="text" class="textBox" id="orderline_0" name="orderline_0" value="#{_product._id}#" />
            </td>
            <td>#{_product._description}#</td>
            <td>
                <input type="text" class="textBox" value="#{quantity()}#" />
            </td>
            <td>#{_product._primaryUOM._description}#</td>
            <td>
                ${ControlBind("Select", {'SelectedValue': 'LK', 'Options' : getReturnTypes(_currentReturn._businessUnit), 'OptionValueKey' : '_code', 'OptionTextKey': '_description' })}$
            </td>
            <td>
                <input type="text" class="textBox" />
            </td>
            <td>%{ toFixedEx(@{unitPrice()}@,2,4) }%</td>
            <td>%{ toFixedEx(@{deposit()}@,2,4) }%</td>
            <td>%{ toFixedEx(@{surcharge()}@,2,4) }%</td>
            <td>%{ toFixedEx(@{extendedPrice()}@,2,2) }%</td>
        </tr>
    </script>

Resulting in:

            <td><input tabindex="0" type="checkbox"></td>
            <td style="width: 125px;" align="left">
                <input tabindex="0" class="textBox" id="orderline_0" name="orderline_0" value="5003" type="text">
            </td>
            <td style="width: 250px;" align="left">Chris Product 3</td>
            <td style="width: 125px;" align="left">
                <input tabindex="0" class="textBox" value="4" type="text">
            </td>
            <td style="width: 125px;" align="left">Each</td>
            <td style="width: 125px;" align="left">
                <select tabindex="0" class="dropdownlist"><option value="OD">1-Outdated</option><option value="REC">2-Recall</option><option value="RTC">3-Reduced to Clear</option><option value="LK" selected="selected">4-Leaker</option><option value="SBD">5-Sour Before Date</option><option value="PW">6-Product Withdrawal</option><option value="DM">7-Damaged</option><option value="TR">8-Tickets Redeemed</option><option value="PL">9-Product Launch</option><option value="BB">Buy Back</option></select>
            </td>
            <td style="width: 125px;" align="left">
                <input tabindex="0" class="textBox" type="text">
            </td>
            <td style="width: 125px;" align="right">81.40</td>
            <td style="width: 125px;" align="right">%{ toFixedEx(rowData.deposit(),2,4) }%</td>
            <td style="width: 125px;" align="right">0.00</td>
            <td style="width: 125px;" align="right">%{ toFixedEx(rowData.extendedPrice(),2,2) }%</td>
  • 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-25T15:53:17+00:00Added an answer on May 25, 2026 at 3:53 pm

    A better way to iterate over the matches is to use .replace with a callback, for example:

    var codeblock = /%\{([\S\s]*?)\}%/g; // note the added capturing group
    template = template.replace(codeblock, function(g0,g1){
        return eval(g1);
    });
    

    Example: http://jsbin.com/owunoy/2

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

Sidebar

Related Questions

I have been working on a template using almost all jquery/javascript. Mostly I am
A] Problem summary: I have JSON data being returned from python to javascript. I
I have problem in some JavaScript that I am writing where the Switch statement
I do not have problem as such but I am quite new to Ruby.
I have JavaScript in my template file, because of the smarty can't include the
It is possible you have Javascript read vars from Django template tags like var
Hi I have problem with adding javascript into a joomla module..I've found some solution,
I have a problem with disabling JavaScript minifier in Liferay 5.2.3. I tried the
I have an interesting problem. I currently have a basic template library that renders
Ok so here is a problem, I have an html template which looks something

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.