0

I have a very large file of source code loaded in Notepad++, and I am trying to use it's regex search capabilities to find all places where a property is used.

I need to find all places where a property DESCR is set. I tried searching for just .DESCR without regex, but there are far too many results for me to sift through. I know that the code I am looking for will either be prefaced with %This. or & and some variable name, followed by .DESCR =.

I've tried using RegExr to construct the regex, but it isn't finding the strings I want. I've looked here to try to understand regex more, but I am missing something still.

EDIT: More descriptions Here are examples of something I would be looking for:
%This.oPosition.DESCR = &DATAREC.Y_BUSINESS_TITLE.Value;
%This.data.DESCR = "";
&data.DESCR = "Analyst";
&oPosition.DESCR = &DATAREC.DESCR.Value;

It should not, however, match on these:
&P_NODE_PIN_DESCR = &NODE_PIN_DESCR;
&qLang.Descr = &sDescr;

I know that I am way off base, but here is what I have tried:

(\%This\.|\&[A-Z]+)\.DESCR = This doesn't pick up anything.
\%This.|\&(A-Z)+.DESCR This picks up on %This but nothing following, and doesn't find anything prefaced by &.
\%This.\w.DESCR =|\&\w+.DESCR = It looks like it's working on RegExr, but it doesn't match properly in Notepad++ (It matches on things like &ACCT_DESCR =)

I'm just not familiar enough with regex to understand what I am missing.

EDIT: Notepad++ search settings: enter image description here

Community
  • 1
  • 1
Cache Staheli
  • 2,897
  • 6
  • 30
  • 41

2 Answers2

1

You can search for (?:%this\.|&)\w+\.DESCR = according to your description. Please untick match case in the search dialog (except you are only searching for This, but not for this or similar.

  • (?:%this\.|&) matches either %this. or & both literally (but case insensitive)
  • \w+ matches one or more word characters, thus letters, numbers or underscore. You could also use [a-z]+ to be stricter and only consider letters - or [a-zA-Z]+ when searching case sensitive
  • \.DESCR = matches .DESCR = literally. If you only want to match DESCR case sensitive, you can use an inline modifier for case sensitivity: \.(?-i)DESCR =
Sebastian Proske
  • 7,985
  • 2
  • 26
  • 36
0

Here's why your attempts didnt work:

  1. You are checking for lowercase only. [A-Z] You need to check for [a-zA-Z] or use the insensitive modifier /i (in this case represented by the "match case" check box

  2. When using the or simple it refers to everything after it until it reaches the end or a closed parentheses

Here's the regex you need

(\%This\.|\&)[A-Za-z]+\.DESCR

If you want to capture only .DESCR you can use this non-capturing groups like so:

(?:(?:\%This\.|\&)[A-Za-z]+)(\.DESCR)

You can then use the back-reference $1 or \1 to replace .DESCR in these specific appearances

https://regex101.com/r/fW9lZ2/2

yosefrow
  • 1,530
  • 12
  • 26