Python Comment Regular Expression

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: