嗨,我正在尝试分割这个字符串(它很长):
Library Catalogue Log off | Borrower record | Course Reading | Collections | A-Z E-Journal list | ILL Request | Help Browse | Search | Results List | Previous Searches | My e-Shelf | Self-Issue | Feedback Selected records: View Selected | Save/Mail | Create Subset | Add to My e-Shelf | Whole set: Select All | Deselect | Rank | Refine | Filter Records 1 - 15 of 101005 (maximum display and sort is 2500 records) 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) 2 Kowalski, Robin M. Cyberbullying : bullying in the digital age / Robin M. Kowalski, Susan P. Limber, Patricia W. Ag 2012. BK Book University Library( 1/ 0) ... 15 Ambrose, Gavin. Approach and language [electronic resource] / Gavin Ambrose, Nigel Aono-Billson. 2011. BK Book
这样我要么回来:
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
运行它时,它会删除所有 header ,但我得到的只是未找到匹配项
。 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));
}
关于Java正则表达式尝试分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9708914/