Scanner scanner = new Scanner(new File(pathf2));
scanner.useDelimiter("########");
String pattern2="^[-a-z0-9R:._-`&=*'`~\"\\+[\\s]]+[\\(]";
Pattern r2 = Pattern.compile(pattern2);
Matcher m2 = r2.matcher(line);
while (m2.find())
{
rel = m2.group();
rel = rel.substring(0, rel.length()-1).trim();
System.out.println("The relation are " + rel);
}
这是我的输入文件....我需要一个匹配块中每个句子中的 3 个字母的正则表达式.. 上面的编码只返回与块中第一行匹配的“agt”。然后它返回“obj”是第二个块的开始。我需要一个块中每行的 3 个字符....如果我在正则表达式中删除“^”,它也需要句子中的第二个单词....请帮助
agt(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@present,ram(icl>volatile_storage>thing,equ>random-access_memory))
obj(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@present,rice(icl>grain>thing))
########
obj(clear(icl>remove>do,plf>thing,obj>thing,ins>thing).@entry.@past,bloodsworth.@topic)
man(clear(icl>remove>do,plf>thing,obj>thing,ins>thing).@entry.@past,ultimately(icl>how,com>ultimate))
ins(clear(icl>remove>do,plf>thing,obj>thing,ins>thing).@entry.@past,evidence(icl>indication>thing))
obj(gather(icl>do,equ>accumulate,plf>thing,agt>thing,obj>thing,plc>thing).@state,evidence(icl>indication>thing))
plf(gather(icl>do,equ>accumulate,plf>thing,agt>thing,obj>thing,plc>thing).@state,from)
mod(stain(icl>appearance>thing).@indef,semen(icl>liquid_body_substance>thing))
obj(from,stain(icl>appearance>thing).@indef)
plc(gather(icl>do,equ>accumulate,plf>thing,agt>thing,obj>thing,plc>thing).@state,panties.@pl)
pos(panties.@pl,victim(icl>unfortunate>thing).@def)
########