XF 2.1 Regex - Remove all instances of string in template? (Or make simple replacement match all?)

Kevin

Well-known member
Hopefully an easy solution... I'm trying to do a template modification do remove chunk of code from a template. Easy enough for a 'simple replacement' till I realized that the exact same chunk of code appears several times and the simple replacement only removes the first match.

Any way to either do a simple replacement but specify all matches or there is a regex I could to do remove the chunk of code? Because the lines in question have opening tags, closing tags, quotes, and all the usual stuff you'd find in a template I'm not sure how to do the regex match.

Thanks
 
The simple replacement works on all matches in my testing. Are you sure you're matching what you think you are (white-space and all)?
 
Hopefully an easy solution... I'm trying to do a template modification do remove chunk of code from a template. Easy enough for a 'simple replacement' till I realized that the exact same chunk of code appears several times and the simple replacement only removes the first match.

Any way to either do a simple replacement but specify all matches or there is a regex I could to do remove the chunk of code? Because the lines in question have opening tags, closing tags, quotes, and all the usual stuff you'd find in a template I'm not sure how to do the regex match.

Thanks
When I've done this in the past, I just copy all the template text to notepad++ and use the built in find / replace, and then paste the edited text back into the XF template editor.
 
I don't usually try to do a global 'replace' in TMS so I just tried it with a simple string and, sure enough, that works so I think @Jeremy P is on the right track in regards to the spacing as the chunk I'm trying to replace look like one instance has an extra tab.

Here's what I'm trying to replace...

2 instances
Code:
<xf:button class="button--small js-attachmentAction" data-action="thumbnail">
     {{ phrase('thumbnail') }}
</xf:button>
1 instance
Code:
<xf:button class="button--small js-attachmentAllAction" data-action="thumbnail">
     {{ phrase('thumbnail') }}
</xf:button>
The one with class 'js-attachmentAllAction' can be done with a straightforward replace but the 'attachmentAction' is the one giving me grief. Thoughts other than creating two nearly identical TMS entries? Any way, for example, to do something like stripping out the extra spaces & tabs from the template and doing the replacement with that the stripped version (using a PHP callback)? :)
 
Any way, for example, to do something like stripping out the extra spaces & tabs from the template and doing the replacement with that the stripped version (using a PHP callback)?
This is pretty much what regular expression matches are all about. Something like:
Code:
/<xf:button class="button--small js-attachment(All)?Action" data-action="thumbnail">.+<\/xf:button>/isU
 
This is pretty much what regular expression matches are all about. Something like:
Code:
/<xf:button class="button--small js-attachment(All)?Action" data-action="thumbnail">.+<\/xf:button>/isU
That works perfectly, thank you! 😎 You have convinced me that I seriously need to get more familiar with regex expressions.
 
Top Bottom