regex_split

The regex_split filter splits the string value by a regular expression.

{% set parts = 'Separate this sentence by spaces,   commas, and   more   spaces.'|regex_split('/[\\s,]+/') %}

The above example returns

[
    0 => Separate
    1 => this
    2 => sentence
    3 => by
    4 => spaces
    5 => commas
    6 => and
    7 => more
    8 => spaces.
]

Arguments

The regex_split filter has the following signature.

regex_split(pattern)

Argument Description
pattern

The regular expression to match and split the string on.

/[a-z]/

Any backslashes in the regular expression need to be double escaped like this: \\

/\\d+/

< Back to the list of filters