Jump to content

Difference between two identical strings

Recommended Posts

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.


 f: Integer;
 c: string;
 b: Integer;
 bla: String;
 k: string;
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)

Link to comment
Share on other sites

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


The RegEx should only pick out ces.



I tried it and it worked - thanks.

Edited by febc6ef940
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...