question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter "replace" not working with regexp

See original GitHub issue

According 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:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
rhenglescommented, May 17, 2016

This needs to be mentioned on the docs!

6reactions
rbveacommented, Apr 16, 2015

Looks like the syntax would be:

replace( r/(https?:\/\/[^ ]+)/ , "<a href=\"$1\">$1</a>" )

(note the r before the regexp)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found