- 
                Notifications
    You must be signed in to change notification settings 
- Fork 34
regex_replace
        Umakant Patil edited this page Aug 14, 2017 
        ·
        6 revisions
      
    A regular expression search and replace on a variable. Use the RegExp from JavaScript.
Only modifiers (flags) 'i' and 'm' are supported in this version.
Backslashes should be escaped e.g. \s
    {$foo = bar}
    {$foo|regex_replace:'/b/':'z'}   //zarNote:- Although jSmart supplies this regex convenience modifier, it is usually better to apply regular expressions in JavaScript, either via custom functions or modifiers. Regular expressions are considered application code and are not part of presentation logic.
| Parameter Position | Type | Required | Default | Description | 
|---|---|---|---|---|
| 1 | string | Yes | n/a | This is the regular expression to be replaced. | 
| 2 | string | Yes | n/a | This is the string of text to replace with. | 
Template:
{$articleTitle = 'Infertility unlikely to\nbe passed on, experts say'}
{* replace each carriage return, tab and new line with a space *}
{$articleTitle}
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}output:
Infertility unlikely to
be passed on, experts say.
Infertility unlikely to be passed on, experts say.
see also regex_replace in PHP Smarty documentation.