Regular Expressions 101

Community Patterns

Community Library Entry

3

Regular Expression
PCRE2 (PHP >=7.3)

/
((^|\s)#(.*)$)|(^\n)|(\n(\s|)+#(.*)$)|([\n\s]+#.*)|([\n\s]{2,}$)
/
gm

Description

This RegEx removes unused elements such as inline comments and blank lines in python code. This will save you tokens and time when using GPT-3+ or ChatGPT to help code and debug.

Submitted by LukeL - 2 years ago (Last modified 2 years ago)