Home > Blockchain >  How to continue searching in the found reqexp result?
How to continue searching in the found reqexp result?

Time:11-17

There is a certain string that I find using regexp, is there an opportunity to check whether there is another one in the found string

For example, I found a string using

(?i)((function|procedure) (. ?(?=stdcall)))

And I want to check if there is a result in it for

(. ?(?=((\s)|(\:))String))

For example, it should find

Function Test(aTest: String; const aPluginCall: TObject): integer; stdcall; export;

But skip

Function Test(aTest: AnsiString; const aPluginCall: TObject): integer; stdcall; export;

or

Function Test: integer; stdcall; export;

CodePudding user response:

You can use

(?si)(function|procedure)((?:(?!function|procedure|stdcall).)*[\s:]String(?:(?!function|procedure).)*)(?=stdcall)

See the regex demo.

Details:

  • (?si) - s enables . to match line break chars and i enables cas e insensitive matching
  • (function|procedure) - Group 1: function or procedure
  • ((?:(?!function|procedure|stdcall).)*[\s:]String(?:(?!function|procedure).)*) - Group 2:
    • (?:(?!function|procedure|stdcall).)* - a char other than line break chars, zero or more but as many as possible occurrences, that does not start a function, procedure or stdcall char sequences
    • [\s:] - a whitespace or :
    • String - a String string
    • (?:(?!function|procedure).)* - a char other than line break chars, zero or more but as many as possible occurrences, that does not start a function or procedure char sequences
  • (?=stdcall) - a positive lookahead that requires stdcall text to appear immediately to the right of the current location.
  • Related