我有以下文字:正則表達式匹配的文本
node [
id 2
label "node 2"
thisIsASampleAttribute 43
]
node [
id 3
label "node 3"
thisIsASampleAttribute 44
]
我想組的每個節點和它的括號內如內容:
node [
id 2
label "node 2"
thisIsASampleAttribute 43
]
不過我我下面的代碼分組的全文:
Pattern p = Pattern.compile("node \\[\n(.*|\n)*?\\]", Pattern.MULTILINE);
Matcher m = p.matcher(text);
while(m.find())
{
System.out.println(m.group());
}
編輯文本:
node [\n" +
" id 2\n" +
" label \"node 2\"\n" +
" thisIsASampleAttribute 43\n" +
" ]\n" +
" node [\n" +
" id 3\n" +
" label \"node 3\"\n" +
" thisIsASampleAttribute 44\n" +
" ]\n"
你有足夠的斜線? – 2016-01-23 01:11:19