XF 2.1 Regex Help

Ozzy47

Well-known member
I have this regex, <xf:if is="\$post\.edit_count && \$post\.canViewHistory\(\)".*\/>

It matches just about everything I am looking for in the post_macros template:
HTML:
<xf:if is="$post.edit_count && $post.canViewHistory()">
                                                <a href="{{ link('posts/history', $post) }}"
                                                    class="actionBar-action actionBar-action--history actionBar-action--menuItem"
                                                    data-xf-click="toggle"
                                                    data-target="#js-post-{$post.post_id} .js-historyTarget"
                                                    data-menu-closer="true">{{ phrase('history') }}</a>

                                                <xf:set var="$hasActionBarMenu" value="{{ true }}" />
                                            </xf:if>

The only thing that is not included it the closing </xf:if> tag, and that needs to be included.
 
#<xf:if is="\$post\.edit_count && \$post\.canViewHistory\(\)".*</xf:if>#sU

Using an OR (|) like @MilkyMeda suggested is also possible, but IMHO using the s-modifier so . also matches newlines is easier.

You'd also want to use the U-modifier so it also correctly works on this input (which is not the case with the regex @MilkyMeda suggested):

Code:
<xf:if is="$post.edit_count && $post.canViewHistory()">
                                                <a href="{{ link('posts/history', $post) }}"
                                                    class="actionBar-action actionBar-action--history actionBar-action--menuItem"
                                                    data-xf-click="toggle"
                                                    data-target="#js-post-{$post.post_id} .js-historyTarget"
                                                    data-menu-closer="true">{{ phrase('history') }}</a>

                                                <xf:set var="$hasActionBarMenu" value="{{ true }}" />
                                            </xf:if><xf:if is="$foo">foo</xf:if>
 
Last edited:
/<xf:if is="\$post\.edit_count && \$post\.canViewHistory\(\)\">(.|\s)+(<\/xf:if>)/

Thanks, I just came up with this and it seems to work as well, <xf:if is="\$post\.edit_count && \$post\.canViewHistory\(\)".[I]\/>.[/I]<\/xf:if> which way is better?
 
To add to this topic, is there a way to search for tab newlines when using regex through template modifications?
 
Last edited:
Trying to do a $1 and $2 replacement. Can someone help with the regex?

#(<xf:macro name="feed_row" arg-item="!">.*?)(<\/li>.*?)#si
 
Last edited:
I am not sure if I understand what you are trying to do ... you've got two star quantifiers (which are the only quantifiers) any you make each one of them ungreedy; imho it would be easiert tu read/understand to just use the U modifier in this case.

What are you trying to match and replace?
 
Thanks for the reply..

In the news_feed_macros template, I am trying to find, <xf:macro name="feed_row" arg-item="!"> and add a opening if statement, then find </li> and add a closing if statement.
 
Okay, I am kinda stumped again. In the PAGE_CONTAINER template, I am wanting to search for this:
HTML:
                    <img src="{{ base_url(property('publicLogoUrl')) }}" srcset="{$srcset}" alt="{$xf.options.boardTitle}"
                        width="{{ property('publicLogoWidth') ?: '' }}" height="{{ property('publicLogoHeight') ?: '' }}" />

Which I find easily like this:
/<img src="{{ base_url\(property\('publicLogoUrl'.+>/isU

Problem is, there are two instances of what I am searching for. I need to change the first one and second one to two different things.

So how can I stop the find after the first instance, and then find only the second instance?
 
Try with pattern:
Code:
#(<div class="p-header-logo.*?)(<img .*?\/>)(.*?<div class="p-nav-smallLogo.*?)(<img.*?\/>)#si
and replacement being
Code:
$1[     first logo replacement goes here     ]$3[      second logo replacement goes here      ]

I suggest you try playing with regex101 as it is very useful.
 
Back
Top Bottom