Search code examples
regexregular-language

Regular expression to find lvalue and rvalue in source code (ignore == )


I am using the regular expression dEF\w+\(\w+\)=.*?; in order to find patterns of the following form:

dEFPFC(pATREF)=dIDOSSEGPfc(pIDOSSeg);
dEFTur(pATREF)=dIDOSSEGTurnaround(pIDOSSeg);

The problem is that it also taking into account patterns that have ==. I don't want that.

this pattern dEFOriDate(pNextEF)==dEFDesDate(pATREF)); should be ignored because it has ==.

I tried using dEF\w+\(\w+\)={1}.*?; but it didn't work


I tested the regular expression on https://regex101.com/.


Solution

  • Add a negative (?!=) lookahead after =:

    dEF\w+\(\w+\)=(?!=).*?;
                  ^^^^^ 
    

    The (?!=) lookahead will fail a match if the = (matched with =) is followed with another =.

    See the regex demo.