A regular expression to match Python single line comment that starts with a #
.
/#.*/g
Matches:
- # This is a comment
- ## This is a comment
Non-matches:
- // This is a comment
- /* This is a comment */
Python Multiline Comment Regular Expression:
If you’re looking for a regex that matches a multiline comment, use this instead:
/"""[\s\S]*?"""/
Matches:
- “”” “””
See Also:
- HTML Comment Regular Expression
- CSS Comment Regular Expression
- JavaScript/PHP/Java/Kotlin/Go/C/Swift/C# Comment Regular Expression