Triple-Quoted String (Python / TS)
Match triple-quoted strings (Python docstrings, TypeScript triple-quote, etc.) including newlines.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\"\"\"([\\s\\S]*?)\"\"\"", "g");
const input = "def foo():\\n \"\"\"Docstring here.\"\"\"\\n pass";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\"\"\"([\\s\\S]*?)\"\"\"")
input_text = "def foo():\\n \"\"\"Docstring here.\"\"\"\\n pass"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`"""([\s\S]*?)"""`)
input := `def foo():\n """Docstring here."""\n pass`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
"""([\s\S]*?)""" (flags: g)Raw source: """([\s\S]*?)"""
How it works
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.