Skip to content

Instantly share code, notes, and snippets.

@renestalder
Created May 13, 2022 09:28
Show Gist options
  • Save renestalder/7e5136b97691afd5dcfc760384092669 to your computer and use it in GitHub Desktop.
Save renestalder/7e5136b97691afd5dcfc760384092669 to your computer and use it in GitHub Desktop.
Search and replace regex to add a namespace to all references in Twig

The regex is made for JavaScript regex engines.

It can, for example, be used in node, or pasted into search field of Visual Studio Code and used for a search/replace.

Search:

(\{%|\{\{)\s*(import|embed|include|source|extends|from)(\s*)(\(?['|"])(.*)(['|"]\)?)([\s\S]*?)(%\}|\}\})

Replace with:

$1 $2$3$4@your-namespace/$5$6$7$8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment