String RegEx Efficent

旧版のRegExはpcre.jitが、8kb以上のストリングをマッチしようとすると、ERRORをだすことがわかった。 ERRORの理由は、(...|...|...|...)の形のORは効率が悪いからである。Negative LookbehindやAtomic Group などを用いて効率のよいRegExを作る必要がある。

explain-regex.php

/(?:'(?:[^\n]*?)(?<!\\)(?>\\\\)*?'(\s*(?='))?)+/su
/(?:"(?:[^\n]*?)(?<!\\)(?>\\\\)*?"(\s*(?="))?)+/su
test1.txt
content:"ab\cd\\ef\\\gh\\\\ij\\\\\kl";
true =>"ab\cd\\ef\\\gh\\\\ij\\\\\kl"◇
test2.txt
content:"a\"bc\"d'ef"gh;
true =>"a\"bc\"d'ef"◇
test3.txt
content:'abc"d\'ef';
true =>'abc"d\'ef'◇
test4.txt
content:"abc\ def";
false
test5.txt
content:"a\'b\"c\ def";
false
test6.txt
content:"abc def";
false
test7.txt
content:"abc""def"     ;
true =>"abc""def"◇
test8.txt
content:"abc" "def";
true =>"abc" "def"◇
test9.txt
content:"abc" "def";
true =>"abc" "def"◇
test10.txt
content:"abc"def";
true =>"abc"◇