0

Live example: https://regexr.com/4rblr

Source markup:

<xf:macro name="breadcrumbs" arg-breadcrumbs="!" arg-navTree="!" arg-selectedNavEntry="{{ null }}" arg-variant="">
    <xf:if contentcheck="true">
        <ul class="p-breadcrumbs {{ $variant ? 'p-breadcrumbs--' . $variant : '' }}"
            itemscope itemtype="https://schema.org/BreadcrumbList">
        <xf:contentcheck>
            <xf:set var="$position" value="{{ 0 }}" />

            <xf:set var="$rootBreadcrumb" value="{$navTree.{$xf.options.rootBreadcrumb}}" />
            <xf:if is="$rootBreadcrumb AND $rootBreadcrumb.href != $xf.uri">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$rootBreadcrumb.href}"
                    arg-value="{$rootBreadcrumb.title}" />
            </xf:if>

            <xf:if is="$selectedNavEntry && $selectedNavEntry.href && $selectedNavEntry.href != $xf.uri && $selectedNavEntry.href != $rootBreadcrumb.href">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$selectedNavEntry.href}"
                    arg-value="{$selectedNavEntry.title}" />
            </xf:if>
            <xf:foreach loop="$breadcrumbs" value="$breadcrumb" if="$breadcrumb.href != $xf.uri">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$breadcrumb.href}"
                    arg-value="{$breadcrumb.value}" />
            </xf:foreach>

        </xf:contentcheck>
        </ul>
    </xf:if>
</xf:macro>

I'm trying to grab the ul.p-breadcrumbs element via regex. I can grab the ul and everything after ok using:

<p.*class.p-breadcrumbs(.*[\s]*)*

And I can select the closing tag with

<\/ul>

However putting them together doesn't work at all:

<ul.*class=.p-breadcrumbs(.*[\s]*)*<\/ul>

I followed this answer: https://www.regextester.com/93456

But it doesn't work with multiline content. If you line break that example and enter more content it breaks the solution. Appreciate any pointers as I'm pulling hair out trying to solve the last bit!

Whitesky
  • 25
  • 10
  • I recommend using an HTML/XML parser. Regex isn't good for this. – CAustin Dec 27 '19 at 02:19
  • Only thing is, I'm working in a forum software (Xenforo) that accepts back-end regex for template modifications. But I would do so out of Xenforo! – Whitesky Dec 27 '19 at 02:35

1 Answers1

-1

I fixed it on my own as a regex novice by fiddling around. The first group needed a ? symbol and I don't know why, other than it somehow makes matches "lazy" and not grab too many characters.

Solution is updated with:

<ul class="p-breadcrumbs(.*?\s)*?<\/ul>

https://regexr.com/4rblr

Perhaps someone with more knowledge could demystify the ? usage for other novices?

Whitesky
  • 25
  • 10