1

I am wanting to remove the icons from the h1 title element in opencart admin panel. I'm trying to use an asterisk as a wildcard for the file name, but it's not working out. The docs says the search data:

<h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>

should be a valid regex pattern, though I'm not familiar with regex. How can I do this correctly in vqmod?

<file name="admin/view/template/*/*.tpl">
    <operation>
        <search regex="true" position="replace"><![CDATA[
            <h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>
        ]]></search>
        <add><![CDATA[      
            <h1><?php echo $heading_title; ?></h1>
        ]]></add>
    </operation>
</file>
Lea
  • 934
  • 9
  • 17
  • 34

2 Answers2

1

In regex, an asterisk * is a quantifier which means match zero or more times.
I think you want to match anything, one or more times. You do that with .+. Ofcourse you want it ungreedy, so the final pattern is .+?.

  • . : match anything
  • + : a quantifier which means match one or more times
  • ? : + followed by ? means to match ungreedy

Let's apply the above in the code:

<h1><img src="view/image/.+?\.png" alt="" /> <?php echo preg_quote($heading_title); ?></h1>
  • We need to escape the dot in \.png
  • We'll use preg_quote() to escape properly regex reserved characters in the $heading_title variable
HamZa
  • 14,671
  • 11
  • 54
  • 75
  • Thanks. In my post I point out the the whole string needs to be a "valid regex pattern". How do I apply that, to this html with the wildcard applied to the image name `

    `
    – Lea Jul 05 '13 at 10:06
  • The search data needs to remain as it appears in the source. If you see this post it might help you understand what I mean http://stackoverflow.com/questions/16624973/vqmod-wildcard-search-using-regex - I need a similar solution, not for a PHP string, but for the html I posted in my previous comment. – Lea Jul 05 '13 at 10:17
  • @Lea Have you tried the solution ? Otherwise I shouldn't have answered since I've no idea what environment this is ... – HamZa Jul 05 '13 at 10:22
  • 1
    @HamZa - The php is not executed - it's static text – Jay Gilford Jul 05 '13 at 10:23
1

In vQmod, the regex still needs to have its delimiters. You are also better off just using a generic search for the <h1> since you are setting it to just the heading title.

<file name="admin/view/template/*/*.tpl">
    <operation>
        <search regex="true" position="replace"><![CDATA[~<h1>.*?</h1>~]]></search>
        <add><![CDATA[<h1><?php echo $heading_title; ?></h1>]]></add>
    </operation>
</file>
dda
  • 6,030
  • 2
  • 25
  • 34
Jay Gilford
  • 15,141
  • 5
  • 37
  • 56