在下面的代码中,如果字符串 s 被附加为 10 或 20,000 个字符,则 Mathematica 内核 seg 错误。
s = "This is the first line.
MAGIC_STRING
Everything after this line should get removed.
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
...";
s = StringReplace[s, RegularExpression@"(^|\\n)[^\\n]*MAGIC_STRING(.|\\n)*"->""]
我认为这主要是 Mathematica 的错,我已经提交了一份错误报告,如果我得到回复,我会在这里跟进。但我也想知道我是否以愚蠢/低效的方式这样做。即使没有,解决 Mathematica 错误的想法也会受到赞赏。