我有一个正则表达式来缩小Laravel视图编译器生成的代码的结果.在编译视图时,正则表达式只不过是缩小HTML而已.我很难设置正则表达式来忽略以":"和"@"(例如... @click="hide(true)" :class="{collapsed: !open}">
)开头的属性,因为alpinejs使用它们.
在HTML代码中:
<select
id="version-switcher"
:class="{test: true}"
aria-label="Localhost version"
class="appearance-none"
@change="window.location = $event.target.value"
>
<option value="https://localhost">Test</option>
<option selected value="https://localhost">Foo</option>
</select>
结果应该是:
<select id="version-switcher" :class="{test: true}" aria-label="Localhost version" class="appearance-none" @change="window.location = $event.target.value"><option value="https://localhost">Test</option><option selected value="https://localhost">Foo</option></select>
然而,结果是:
<select id="version-switcher":class="{test: true}" aria-label="Localhost version" class="appearance-none"@change="window.location = $event.target.value"><option value="https://localhost">Test</option><option selected value="https://localhost">Foo</option></select>
请注意,以:开头的属性和以@开头的属性与前一个属性没有区别.正则表达式是:return preg_replace('/<!--(.*?)-->|\s\B/um', '', $html);
有人能帮我解决这个问题吗?