add # comment to python code

27 views
Skip to first unread message

John Mitchell

unread,
Sep 21, 2023, 1:26:22 PM9/21/23
to BBEdit Talk
my search string is:  ^\s*print
my replace string is:  #\0

however it goes over the end of a blank line to connect with a next "print..."
How do I stop the multiline operation?

tia

Rich Siegel

unread,
Sep 21, 2023, 1:55:55 PM9/21/23
to BBEdit Talk
You can use a (?-s) at the beginning of the pattern.

Or you could use the "Un/Comment" command on the Text menu. :-)

Enjoy,

R.

--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.

Bruce Van Allen

unread,
Sep 21, 2023, 2:34:39 PM9/21/23
to 'anotherhoward' via BBEdit Talk
\s* stands for zero or more whitespace characters, including \n and \r (newlines).

Two ways (at least) to get what you want:

1. Instead of \s, use a character class. [ \t] defines a character class with a spacebar space and a tab.

* All of these start at beginning of line due to ‘^’ anchor.

^[ \t]*print # zero or more spaces or tabs before ‘print’

^[ \t]print # one tab or space before ‘print'

^[ \t]+print # one or more spaces or tabs before ‘print'


2. Use \h instead of [ \t] or \s; \h stands for horizontal whitespace, applies more widely to horizontal whitespace characters.

^\h*print

^\hprint

^\h+print

HTH

— Bruce

_bruce__van_allen__santa_cruz_ca_
Reply all
Reply to author
Forward
0 new messages