#260

Product support

Visit this product's website for support.

Categories

  • Developer Tools
  • Utility

Twig PCRE Filters for OctoberCMS. This enables support for using Pearl-compatible-regular-expression (regex) PHP functions within your Twig markup.

Supported functions:

Examples:

As filters:

{{ subject | preg_filter(pattern, replacement, limit) }}

{{ subject | preg_grep(pattern) }}

{{ subject | preg_match(pattern) }}

{{ subject | preg_quote(delimiter) }}

{{ subject | preg_replace(pattern, replacement, limit) }}

{{ subject | preg_split(pattern) }}

As functions:

{{ preg_filter(subject, pattern, replacement, limit) }}

{{ preg_grep(subject, pattern) }}

{{ preg_match(subject, pattern) }}

{{ preg_quote(subject, delimiter) }}

{{ preg_replace(subject, pattern, replacement, limit) }}

{{ preg_split(subject, pattern) }}

Please read the PHP docs for a more detailed explanation of all functions.

Usage Examples:

Simple Word Replacement

{{ "This is a simple example." | preg_replace('/simple/', 'beautiful') }}

will output:

This is a beautiful example.

Whitespace cleaning up (Specifically from the results of a Twig macro)

{% macro generateItemUrl(item, falseLink) %}
    {% if (falseLink) or item.url is empty %}
        #
    {% else %}
        {{ item.url }}
    {% endif %}
{% endmacro %}

<a href="{{ _self.generateItemUrl(item, false) | preg_replace('/\\s+/', ' ') | trim | raw }}">{{ item.name }}</a>
1.0.3

Fixed typo in composer.json

Oct 09, 2017

1.0.2

Add support for preg_find and composer

Oct 09, 2017

1.0.1

First version of TwigPCRE

Mar 25, 2017