返回列表 发帖
本帖最后由 523066680 于 2023-3-12 00:23 编辑

其实我看题主四楼和五楼的例子都可以用  );  来限定末尾。
当然更复杂的情况且有必要的话可以考虑设计grammar来解决

抄了一段perl6的文法案例
grammar pair {
    token TOP     { <func> }
    rule func    { <name> '(s' <.ws> <string> ')' }
    rule name    { [\w]+ }
    rule string  {
        (:ignoremark \") ~ \"
        [
            \w |
            [ '\\' <[\\/bfnrt"():]> ] |
            <-[\\\"\n\t]>+
        ]*
    }
};
my $match = pair.parse('abc(s "\\:\/())))abc\([^\)]*[^\(]*\)")');
say $match;COPY
结果
「abc(s "\:\/())))abc\([^\)]*[^\(]*\)")」
func => 「abc(s "\:\/())))abc\([^\)]*[^\(]*\)")」
  name => 「abc」
  string => 「"\:\/())))abc\([^\)]*[^\(]*\)"
   0 => 「"」COPY
并没有解决问题 (逃
[url=][/url]

TOP

返回列表