Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are negative lookbehind in regex searches possible in Geany?

Geany's documentation on negative assertions makes it look like they're possible.

For reference, this works and gives me results:

pcregrep -r "(?<!= )function\(" src/main-js/

But the same regex, or any regex with a negative lookbehind, gives me no result when launched from Geany (v 1.24.1)

enter image description here

Where is the problem? Is the documentation wrong?

Precision: the topic isn't about how to avoid doing a negative look behind, but about how to do any standard PCRE negative look behind.

like image 586
Denys Séguret Avatar asked Mar 13 '15 13:03

Denys Séguret


1 Answers

I got support from the Geany developers on Freenode, and it was very helpful. Here is what they told me:

The documented RE syntax only applies to the RE engine directly used by Geany (e.g. in Find), but the Find in Files features calls the grep tool (as configured in preferences->tools->grep), which has its own syntax. For GNU grep, you can add "-P" to the "Extra options" field in the dialog

However, after you tried it, you had this error:

/bin/grep: conflicting matchers specified

... to which I was told this was a Geany bug. Geany calls grep -E, and -P is not compatible with it.

Your only workaround is to have a shell script calling grep with -P instead of -E, and use this script. You should be able to configure the grep tool to call in Geany preferences.

An example of said shell script:

#!/bin/sh

matchopts=$(echo "$1" | tr E P)
shift

exec grep $matchopts "$@"

Geany uses either -F or -E (these are the only available engines in POSIX grep) for grep, hence why you can't pass -P.

I've reported the bug to the Geany developers.

like image 103
Florian Margaine Avatar answered Oct 02 '22 04:10

Florian Margaine