Filter "replace" not working with regexp
See original GitHub issueAccording to the release v1.1.0 ( https://github.com/mozilla/nunjucks/releases/tag/v1.1.0 ), the filter replace
should accept RegExps for the first argument.
I am trying this
... | replace( /(https?:\/\/[^ ]+)/ , "<a href=\"$1\">$1</a>" )
And it is triggering: Template render error: unexpected token: /
Am I being noob somewhere?
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
regex: how to replace all occurrences of a string within ...
i have tried to use positive lookahead as to not consume the string in which i want to replace characters, but somehow i...
Read more >Use regex in replace filter - Craft CMS Stack Exchange
The replace filter now supports regular expressions, by setting the first argument to a string that begins and ends with forward slashes, e.g....
Read more >Find and replace text using regular expressions - JetBrains
When you want to search and replace specific patterns of text, use regular expressions. They can help you in pattern matching, parsing, filtering...
Read more >Regex.Replace Method (System.Text.RegularExpressions)
In a specified input string, replaces strings that match a regular expression pattern with a specified replacement string.
Read more >Regex Character Classes not working in search-replace
The problem is that regex syntax uses square brackets (to specify character classes), and TiddlyWiki filter syntax also uses square brackets ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This needs to be mentioned on the docs!
Looks like the syntax would be:
replace( r/(https?:\/\/[^ ]+)/ , "<a href=\"$1\">$1</a>" )
(note the r before the regexp)