次のようなものに一致する正規表現があります: asdasd[text]; 一度に 1 ステップずつ正常に動作しますが、次のような場合:
$badinput="add[2,5,525];print['peron'];print['asd','cgfg];time;print['iudofiusdoif'];"; #time should not be matched
これは今のところコードです:
verify($badinput);
sub verify
{
#returns 1 if it's ok, or the text that breaks the match
my $inp = pop;
if ($inp =~ /^(?:\w{2,6}\[(?<!\\\[).*?\](?<!\\\]);)+$/s)
{
return 1;
}else{
return 0; #should be the text that breaks the match or the char number
};
}
最初の命令が一致した場合は、何があっても 1 を返します。どうすればこれを解決できますか?