USING %STRING% INSTEAD OF {{STRING}} IN A REGEX

Total Post:108

Points:756
HTML5 
 1708  View(s)
Ratings:
Rate this:

To translate some strings in my HTML, I'm using the following function which is working totally fine to replace every string coming in double curly braces:

var translation = html.replace(/\{[^\}]*\}/g, function(match){

    // where the magic happens
});


How can I change the RegEx to match the pattern %string% instead of {{string}}?

  1. Post:183

    Points:1285
    Re: Using %string% instead of {{string}} in a RegEx

    Hi John!

    Your current pattern actually doesn't match double curly braces, it matches only single curly braces, but anyway if you want to match %string% then you can use:

    /%[^%]*%/g

      Modified On Mar-31-2018 03:34:59 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!