I have a text that is a source-code file, I need to find the first parameter of all calls of this function. That can be called in this 2 ways. I’m completely dumb in regex.
lang('FOUND') and lang('FOUND',[loremipsum])
FOUND should be anything, is this value that I’m searching.
I will execute the Regexp in delphi, but I think regular expression is language independent
EDIT
Using the @Ken White answer and this Video I did this code, and works fine!
Regular expression: (?:lang\s*\(\s*')(.*?)(?:'\s*\)|'\s*\,\s*\[.*\]\s*\))
Include the Unit PerlRegEx on Uses
procedure TForm1.Button1Click(Sender: TObject);
var
Regex: TPerlRegEx;
begin
Regex := TPerlRegEx.Create();
Regex.RegEx := '(?:lang\s*\(\s*'')(.*?)(?:''\s*\)|''\s*,\s*\[.*\]\s*\))';
Regex.Options := [preCaseless, preMultiLine];
Regex.Subject := Memo1.Text;
if Regex.Match then
begin
repeat
Memo2.Lines.Add( Regex.Groups[1] );
until not Regex.MatchAgain;
end;
end;
(All of the code below was generated by Regex Buddy; I also used it to create the regex used.
SubjectStringis the content of your source file, loaded into a string; you can load the source file into a stringlist, for instance, and pass theText.)Using
TPerlRegex, available from the RegEx Buddy website, you can useUsing Delphi XE’s regex support (
use Regex), you can useIn both cases, the text you want (the part between the parentheses) will be in capturing group 1 of each match.
I seem to recall from other questions that you’re using Delphi 7, so the first will probably be the best option.