febc6ef940 Posted December 27, 2015 Share Posted December 27, 2015 I'm having problems getting my script to work. When I run [k := PregMatch(bla, c);] the script outputs an empty line with WriteLn() but if I run [k := PregMatch('/^(?!(.).\1)[uitiedåhwtritnåtoiirsrmce]{3}$/im', c)] the script runs as expected giving me the first RegEx match in the loaded file. When I use WriteLn(bla); it will output the exact same string as used successfully above. There must be a hidden difference between the two strings but I cannot see it. Code below. var f: Integer; c: string; b: Integer; bla: String; k: string; begin f := OpenFile(IncludesPath + 'done.txt', True); ReadFileString(f, c, FileSize(f)); for b := 3 to 15 do begin bla := '''/^(?!(.).\1)[uitiedåhwtritnåtoiirsrmce]{' + IntToStr(b) + '}$/im'''; k := PregMatch(bla, c); //k := PregMatch('/^(?!(.).\1)[uitiedåhwtritnåtoiirsrmce]{3}$/im', c) WriteLn(k); end; Closefile(f); end. Quote Link to comment Share on other sites More sharing options...
Wanted Posted December 27, 2015 Share Posted December 27, 2015 Too many ' at the beginning and end. Try just bla := '/^(?!(.).\1)[uitiedåhwtritnåtoiirsrmce]{' + IntToStr(b) + '}$/im'; Could help more if I had something to use for file f to test. Quote Link to comment Share on other sites More sharing options...
febc6ef940 Posted December 28, 2015 Author Share Posted December 28, 2015 (edited) Thanks for taking an interest to my question. I put in the three apostrophes because the function I use goes like PregMatch('..', integer) and the 2nd and 3rd ' gets interpreted as a single apostrophe (just like \' would work in most other languages). But perhaps the apostrophes in PregMatch is not needed when referencing an object - I will have to try that when I get home. For a file you could use something like xxx xes ces yyy The RegEx should only pick out ces. Edit: I tried it and it worked - thanks. Edited December 28, 2015 by febc6ef940 Quote Link to comment Share on other sites More sharing options...