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 andi
enables cas e insensitive matching(function|procedure)
- Group 1:function
orprocedure
((?:(?!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 afunction
,procedure
orstdcall
char sequences[\s:]
- a whitespace or:
String
- aString
string(?:(?!function|procedure).)*
- a char other than line break chars, zero or more but as many as possible occurrences, that does not start afunction
orprocedure
char sequences
(?=stdcall)
- a positive lookahead that requiresstdcall
text to appear immediately to the right of the current location.