【发布时间】:2023-03-19 22:13:01
【问题描述】:
在解析 CFG 文件中的行字符串时遇到问题,
输入字符串是:
String str = "The <animal> loves to <activity>.";
我尝试使用带有正则表达式的拆分来按非终结符 () 进行拆分,但是它没有产生预期的结果:
我尝试过的:
str.split("(?=<)");
Output:
"The ", "<animal> loves to", "<activity>."
期望的输出:
"The ", "<animal>", " loves to ", "<activity>", "."
【问题讨论】: