Sublime Forum

Comment or remove multiple lines following a pattern rule

#1

Hi.

For debugging purposes, I usually spread out lots of “print out” statements in my code. But for a fast localization of them, I use a sort of tag in order to tell where is the beginning of the debug part and where is the end of it.
For example:

# important code here
variable_x = 0
variable_y = 1
### DEBUG
print(variable_x)
print(variable_y)
### --- DEBUG

In this example, ### DEBUG delimit the beginning of the debug part and ### — DEBUG delimit the end of it.
When I don’t want the debug outputs for a while, I have to go through which one of them commenting them out.
And when I’m done debugging I also have to go through which one of them removing them.

Is there faster way to do these tasks (commenting out and removing), since I have a pattern delimiting my debug parts?
Thanks.

0 Likes

#2

You could do a findall with regex : (?s)### DEBUG.*?### — DEBUG and then every occurrence should be selected so you can remove them or comment them easily

0 Likes

#3

Thanks!
That works great.

Do you think it’s possible to select only the internal part? That is, not considering the delimiters itself (### DEBUG and ### — DEBUG)

0 Likes

#4

Yes, with look-ahead and look-behind:

(?s)(?<=### DEBUG\n).*?(?=### — DEBUG)

0 Likes