Are negative searches in the regular search in Geany possible?

Geany's documentation of negative claims pretends to be possible.

For reference, this works and gives me the results:

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

But the same regular expression or any regular expression with a negative lookbehind does not give me a result when starting from Geany (v 1.24.1)

enter image description here

Where is the problem? Incorrect documentation?

Accuracy: the topic is not about how to avoid a negative appearance, but about how to make any standard negative appearance of PCRE.

+6
source share
2 answers

I got support from geany developers on freenode. Very useful. Here is what they told me:

The documented RE syntax only applies to the RE mechanism directly used by Geany (for example, in Find), but the Find in Files functions call the grep tool (as specified in settings-> tools-> grep), which has its own syntax. For GNU grep, you can add "-P" to the Advanced Options field in the dialog box

However, after you tried, you had this error:

/ bin / grep: conflicting matches specified

... who was told that this is a geany mistake. Geany calls grep -E , and -P incompatible with it.

The only workaround is a shell script calling grep with -P instead of -E and using this script. You should be able to configure grep to be called in geany settings.

An example of the specified shell script:

 #!/bin/sh matchopts=$(echo "$1" | tr EP) shift exec grep $matchopts " $@ " 

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

I reported the error to geany developers.

+5
source

Another workaround is to avoid a negative lookbehind statement ... but it is much uglier:

 (^.?|[^=] |=[^ ]|[^=][^ ])function 
+1
source

Source: https://habr.com/ru/post/983749/


All Articles