3

How can I find all lines in Delphi source code using GExperts grep search which contain a string literal instead of a resource string, except those lines which are marked as 'do not translate'?

Example:

this line should match

  ShowMessage('Fatal error! Save all data and restart the application');

this line should not match

  FieldByName('End Date').Clear; // do not translate

(Asking specifically about GExpert as it has a limited grep implementation afaik)

mjn
  • 36,362
  • 28
  • 176
  • 378

1 Answers1

2

Regular Expressions cannot be negated in general.

Since you want to negate a portion of the search, this comes as close as I could get it within the RegEx boundaries that GExpers Grep Search understands:

\'.*\'.*[^n][^o][^t][^ ][^t][^r][^a][^n][^s][^l][^a][^t][^e]$

Edit: Forgot the end-of-line $ marker, as GExperts Grep Search cannot do without.

blokhead explains why you cannot negate in general.

This Visual Studio Quick Search uses the tilde for negation, but the GExperts Grep Search cannot.

The grep command-line search has the -v (reverse) option to negate a complete search (but not a partial search).

A perfect manual negation gets complicated very rapidly.

--jeroen

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • when I do this I just do a positve search with grep and then pipe it into a negative one using -v – David Heffernan Mar 07 '11 at 14:23
  • 2
    How do you pipe a GExperts Grep Search? – Jeroen Wiert Pluimers Mar 07 '11 at 14:45
  • 2
    @David: how do you make that output clickable, so you can jump to source lines in the editor? I think that is what `mjn` is after. I remember (but forgot which IDE that is), you can have tools output in the output window, to make it clickable. Do you know if that is possible? – Jeroen Wiert Pluimers Mar 07 '11 at 16:16
  • @Jeroen You can't do that with grep. I use grep for things like this because I actually get the results I want! It would be nice if I could jump straight to the match, but first priority is usually getting the right match. – David Heffernan Mar 07 '11 at 16:19
  • The expression gives false positives, for example with: `if Pos('.', PropName) > 0 then // do not translate` – mjn Mar 08 '11 at 08:16
  • @mjn: sorry, I forgot to put in the $, it works here, let me know if it works for you. – Jeroen Wiert Pluimers Mar 08 '11 at 10:03
  • @David: the problem is that @mjn wants to negate only a *part* of the expression, and that is something Regular Expressions do not support at all, nor `grep -v` does. – Jeroen Wiert Pluimers Mar 08 '11 at 12:01