In VSCode, attempting to search for print( and print ( - but only if not followed by #
This is my first time attempting a regex search in VSCode...
Examples:
print ('Test One') - MATCH
print( 'Test Two') - MATCH
#print('Test Fee') - SKIPPED
I understand from this question that VSCode lacks negative lookbehind.
Ordinarily, in the ^F (search function) I would use something like (untested):
/w*(?<!#)print
but I am getting the error that the regex is invalid.
Can anyone suggest a workaround - or have I just fat-fingered the regex ?
UPDATE NOTE: Starting with VS Code 1.31, infinite-width lookbehinds are supported.
However, in the current scenario, you do not have to use a lookbehind based solution, you may use
^\s*print\s*\(
See the regex demo
Note that in case you only want to match text on the same lines, it may be a better idea to replace \s with [ \t], or [^\S\n].
Details
^ - start of a line\s* - 0+ whitespacesprint - a literal substring\s* - 0+ whitespaces\( - a ( char (must be escaped to match a literal ().NOTE that actually VSCode still supports lookaheads, but you need to enable search.usePCRE2 option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With