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 passMatches
"""Docstring here."""
Input
a = """line1\nline2""" b = """third"""Matches
"""line1\nline2""""""third"""
Input
no triple quotesNo 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
Related patterns
Python f-String Expression
Text ProcessingMatch `{expression}` placeholders inside Python f-strings (or any single-brace template syntax).
Base64 String
Text ProcessingMatch Base64-encoded strings, including proper padding with = and == characters.
Python Import Statement
Text ProcessingMatch Python `import x` and `from x import y` statements, capturing the module and target.
Hashtag
Text ProcessingMatch hashtags (# followed by word characters) in social media posts, including accented Latin characters.