Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
kubbo122

Problem with regex in product name (TPL thirtybees 1.0.8)

Question

0
 

Hellou, I need put regex ^.gold|Gold|GOLD. in product.tpl (thirtybees 1.0.8) and check if product name consist gold or Gold or GOLD. If product name consist in product name for example Anchor blue Gold then I need create product flag. Is there possible? I try it, but function is not working correctly.

{if (preg_match('^.*gold|gold|GOLD.*', {$product->name|escape:'html':'UTF-8'}))}
                <span class="new-box">
                        <span class="zlato-label">GOLD 24K</span>
            {elseif(preg_match('^.*rosegold|Rosegold|ROSEGOLD.*', {$product->name|escape:'html':'UTF-8'}))}
                <span class="new-box">
                        <span class="zlato-label">Rose GOLD 24K</span>
            {else}
                <span class="new-box">
                        <span class="new-label">Nothing</span>
            {/if}

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Regular expression is invalid, it should be enclosed in start/end delimiters, ie '/^*gold|gold|GOLD.*/' where / is a delimiter. Also, drop the escape:'html':'UTF-8' part.

It should look like this:

{if (preg_match('/^.*gold|gold|GOLD.*/', $product->name))}
...
{/if}

 

Share this post


Link to post
Share on other sites
  • 0

I am no regex expert, but shouldn't it be:

Quote

\b(?:gold|Gold|GOLD)\b

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×