
使用a
Matcher来标识要保留的部分,而不是要拆分的部分:
String s = "hello^world'this*has two tokens'";Pattern pattern = Pattern.compile("([a-zA-Z0-9]+|'[^']*')+");Matcher matcher = pattern.matcher(s);while (matcher.find()) { System.out.println(matcher.group(0));}看到它在线上工作:ideone
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)