Selection regex for a Python function

7 views
Skip to first unread message

Derek

unread,
Jan 1, 2010, 6:57:28 PM1/1/10
to Click Config
Here is a regex that seems to work well for selecting a Python
function.

Pattern: ^[ \t]*def\ [_a-z][_a-z0-9]*\([^\n]*\):\n ([ \t]*)[^\n]*\n
(?:(?:\1[^\n]*\n)|[ \t]*\n)*
Flags: I, M, X

The pattern is pretty busy to look at, but it was easy enough to
write. You can keep the configuration window open while you
experiment with a new pattern, so it's easy to see what does or
doesn't work. Just click Add and Apply each time you edit it.

Derek

unread,
Jan 27, 2010, 6:30:50 PM1/27/10
to Click Config
Here's a newer version. Slightly more rugged, and it will also select
if the lines start with '#'.

Pattern: ^((\#?)[ \t]*)def\ +[_a-z][_a-z0-9]*\ *\([^:]*\):\n (\1
([ \t]*)).*\n (?: (?:\3.*\n) | [ \t]*\n | (?:\3.*$) )*
Flags: I, M, X

Reply all
Reply to author
Forward
0 new messages