Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java正则表达式正在尝试拆分字符串_Java_Regex_Pattern Matching - Fatal编程技术网

Java正则表达式正在尝试拆分字符串

Java正则表达式正在尝试拆分字符串,java,regex,pattern-matching,Java,Regex,Pattern Matching,嗨,我正试图把这根绳子分开(它很长): 所以我要么回去: 1 Drower, E. S. (Ethel Stefana), Lady, b. 1879. Lady E.S. Drower’s scholarly correspondence : an intrepid English autodidact in Iraq / edited by 2012. BK Book University Library( 1/ 0) // Or 1 Drower, E. S. (Ethel Stefa

嗨,我正试图把这根绳子分开(它很长):

所以我要么回去:

1 Drower, E. S. (Ethel Stefana), Lady, b. 1879. Lady E.S. Drower’s scholarly correspondence : an intrepid English autodidact in Iraq / edited by 2012. BK Book University Library( 1/ 0)

// Or

1 Drower, E. S. (Ethel Stefana), Lady, b. 1879. Lady E.S. Drower’s scholarly correspondence : an intrepid English autodidact in Iraq 
这只是一个例子,1号Drower,E.S。。。不会是静态的。虽然每次输入都不同(细节在1和2之间),但字符串的总体布局始终相同

我有:

String top = ".*         (.*)";
String bottom = "\( \d/ \d\)\W*";
Pattern p = Pattern.compile(top); //+bottom
Matcher matcher = p.matcher(td); //td is the input String
String items = matcher.group();
System.out.println(items);
当我用
top
运行它时,它意味着删除所有的头,但我得到的是
没有找到匹配项
bottom
是我尝试拆分字符串的其余部分

如果需要的话,我可以把所有的输入都发到15号。我需要的是分割输入字符串,这样我就可以处理15个结果中的每一个


谢谢你的帮助

这将为您提供两种输入。这就是你想要的

String text = "Library Catalogue Log off ..."; \\truncated text

Pattern p = Pattern.compile("((1 Drower.+Iraq).+0\\)).+2 Kowalski");
Matcher m = p.matcher(text);
if (m.find()) {
    System.out.println(m.group(1));
    System.out.println(m.group(2));
}

首先,您需要将标题与结果数据分开。假设每次都有9个空格块,您可以使用以下内容:
*\s{9}(.*)

接下来,您需要将数据解析为行,这将更加困难,因为您没有行分隔符。您所能做的最好的事情是假设行的分隔方式是:一个空格,然后是一个或多个数字,然后是另一个空格


((?在某种程度上是的。但问题是,输入不是静态的,输入将根据搜索结果而改变。对不起,我应该提到这一点。但是,输入字符串的布局不会改变。数字1只是第一个搜索结果,它将上升到15个结果。如果需要,我可以将所有输入发布到数字15。所以你需要按照我的理解分割所有搜索结果?是的,这是正确的。例如:[1 Drower,E.S..]应该是一个字符串,[2 Kowalski,Robin M..]最多[15 Ambrose,Gavin..]应该是下一个字符串。此输入根据搜索结果而变化。但输入字符串的布局将始终相同。因此,除非结果少于15个,否则1、2、3..15将始终存在
String text = "Library Catalogue Log off ..."; \\truncated text

Pattern p = Pattern.compile("((1 Drower.+Iraq).+0\\)).+2 Kowalski");
Matcher m = p.matcher(text);
if (m.find()) {
    System.out.println(m.group(1));
    System.out.println(m.group(2));
}