regex_replace

Applies a regular expression operation on the input. This filter accepts two input values: one is the pattern, the second is the replacement.

Example:

    <$mt:EntryTitle regex_replace="/\s*\[.+?\]\s*$/",""$>

This would strip any bracketed phrase from the end of the entry title field.

This page was last updated on 2008-02-23, 13:22. [Edit]

2 Notes

Note that the "g" global modifier is valid here, which will find all occurrences, not just one. Extending the above example:

<$mt:EntryTitle regex_replace="/\s*\[.+?\]\s*$/g",""$>

List entry categories if their label is within the set Explore, Savor, Inside, Offbeat, or Celebrate and then glue them with ", ". (The regex_replace modifiers remove extra glue from beginning, end, and between categories that don't match the if statement)

<mt:EntryCategories glue=", " regex_replace="/(,\s+)+/":", " regex_replace="/,\s+$/":"" regex_replace="/^\s+,\s+/":"">
    <mt:If tag="CategoryLabel" like="(Explore|Savor|Inside|Offbeat|Celebrate)">
        <a href="<$mt:CategoryArchiveLink$>"><$mt:CategoryLabel$></a>
    </mt:If>
</mt:EntryCategories>

This is only here as an example, a much better solution would be to use mt:SevVarBlock with function="push" attribute and then output with mt:Loop

Leave a note

Have a question? Please use the MT Forums. Notes submitted on documentation should pertain to tips & hints regarding documentation. Your note may be removed once its contents have been integrated into the body of the page.