我有这个 Ruby 代码:
line = "this is u.s.a. please come home. where are you"
res = line.split(/(.*?[.!?](?:["')\]}]|(?:<.*>))*[\s])/)
它返回["", "this is u.s.a. ", "", "please come home. ", "where are you"]
。
但是当我在 Java 中尝试相同的正则表达式和相同的代码时:
String line = "this is u.s.a. please come home. where are you";
String[] res = line.split("^(.*?[.!?]((?:([\"')\\]}])|(?:<.*>))*)[\\s])");
它只返回两个元素:{ "" , "please come home. where are you"}
.
我的 Java 正则表达式有什么问题?