Text Processingflags: g

Triple-Quoted String (Python / TS)

Match triple-quoted strings (Python docstrings, TypeScript triple-quote, etc.) including newlines.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
"""([\s\S]*?)"""   (flags: g)

Raw source: """([\s\S]*?)"""

How it works

The opening and closing """ bracket the string. ([\s\S]*?) is the lazy any-character-including-newline pattern: [\s\S] is the universal-character idiom (avoids needing the s/dotAll flag), and *? keeps the match minimal so adjacent triple-quote blocks don't merge.

Examples

Input

def foo():\n """Docstring here."""\n pass

Matches

  • """Docstring here."""

Input

a = """line1\nline2""" b = """third"""

Matches

  • """line1\nline2"""
  • """third"""

Input

no triple quotes

No match

Common use cases

  • Python docstring extraction for documentation tools
  • Linting raw SQL or shell snippets in source
  • Code-comment parsers
  • Migration tooling between quote styles