我会有这样的话
String text = [ name abc ]
String text = [ name # abcd]
String text = [ name - abcd]
String text = [ name abcde ]
我想将这些单词拆分为abc,abcd,abcde
这里的分隔符可以是onlyspaces,spaces#spaces,spaces-spaces和nospace。
我要匹配此正则表达式
Pattern pat = Pattern.compile("\[\s*name\s*(-|#)\s*[a-z0-9]+\s*\]",Pattern.CASE_INSENSITIVE);
Matcher matcher = pat.matcher(text);
while (matcher.find()) {
String subseq = matcher.group();
String extractName = subseq.split("(-|#|\\s*)",2)[1].replaceAll("]","").trim();
}
此代码无法用于[name mynameisDON],但适用于[name:abc]
我想知道什么正则表达式传递给此拆分函数,以便我可以实现自己想要的东西。