Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→regex-jinja-specificnext

regex-jinja-specific4.2.1

Regular expression for detecting Python-specific Jinja code

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ISJINJASPECIFI…
  • API — VERSION
  • Changelog

Development is frozen. The published package, documentation, examples, and changelog remain available.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Inline conditional ordering is shared by Jinja and Nunjucks
  • Detect Jinja namespace assignment syntax
  • Find Jinja format filter markers, including whitespace around the call

Purpose

Find textual hints associated with Jinja namespace assignments and format filters. Nunjucks and Jinja share most syntax, and extensions can add similar functions or filters to other engines, so these matches do not prove an engine’s identity.

  • Namespace assignment markers, such as set ns = namespace (total=0). The set keyword must be separate from the assigned name. This hint uses ASCII word characters for assignment names.
  • Format filter markers, such as |format( or | format (. Whitespace around the filter name and opening parenthesis is accepted.

The regex searches substrings, including prose, quoted text, comments, and invalid format expressions. It does not parse template tokens or validate printf strings. Use detect-templating-language for refinement based on live template syntax.

Inline if expressions are shared syntax and are excluded as Jinja-specific evidence. Nunjucks supports inline conditionals, including an optional else.opens in a new tab

API — isJinjaSpecific()

The main function isJinjaSpecific() is imported like this:

Returns a fresh global, case-insensitive RegExp, /.../gi. Use it with RegExp.prototype.exec() or String.prototype.match(). Create a fresh regex for independent .test() calls, or reset lastIndex to zero.

Formatting matches now contain the filter marker itself. The earlier pattern included the preceding quoted numeric format string:

const input = '"%.2f"|format(price)';

// Earlier match: ['"%.2f"|format(']
input.match(isJinjaSpecific()); // ["|format("]

Whitespace within the marker is preserved in each match. For example, "%s" | format (name) produces | format (.

API — version

You can import version:

Permalink to changelogChangelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab