下面是我的文字
Welcome to java programming 1) Oops concepts a) Encapsulation A) Abstraction I) Inheritance • Polymorphism
2)sample program on java 1.Project source code
sample text files • sample.txt b)sam.txt我想拆分文本基于以下模式,并删除项目符号
1)any bullet 1)I)a)A)•
2)followed by space
3)followed by uppercase word因此,我希望生成以下结果
Welcome to java programming
Oops concepts
Encapsulation
Abstraction
Inheritance
Polymorphism
sample program on java
Project source code
Please suggest me how to do this
sample text files
sample.txtsam.txt谢谢
发布于 2013-08-08 15:08:27
这将会起作用:
public static void main(String[] args) throws Exception {
final String s = "Welcome to java programming 1) Oops concepts a) Encapsulation A) Abstraction I) Inheritance • Polymorphism";
final String[] split = s.split("\\s*(\\w\\)|•)\\s*");
for (final String bullet : split) {
System.out.println(bullet);
}
}正则表达式是
\\s*(\\w\\)|•)\\s*\\s* -零个或多个spaces(\\w\\)|•) -后跟括号或项目符号的数字或字母point\\s* -零个或多个空格输出:
Welcome to java programming
Oops concepts
Encapsulation
Abstraction
Inheritance
Polymorphism发布于 2013-08-08 17:53:02
下面的基于正则表达式的正则表达式应该对你有效:
String s = "Welcome to java programming 1) Oops concepts a) Encapsulation A) Abstraction I) Inheritance • Polymorphism";
String[] arr = s.split("\\s*([a-zA-Z\\d][).]|•)\\s*(?=[A-Z])");
System.out.println("Split => " + Arrays.toString(tok));输出:
Split => [Welcome to java programming, Oops concepts, Encapsulation, Abstraction, Inheritance, Polymorphism]发布于 2013-08-08 15:16:10
你也可以试试这个
String str="Welcome to java programming 1) Oops concepts a) Encapsulation A) Abstraction I) Inheritance • Polymorphism" ;
String newStr=str.replaceAll("(?i)\\s*([\\d\\w]\\)|•)\\s*"," ISseperatorIS ");
String[] arr=newStr.split("ISseperatorIS ");
for(String i:arr){
System.out.println(i);
}输出输出
Welcome to java programming
Oops concepts
Encapsulation
Abstraction
Inheritance
Polymorphismhttps://stackoverflow.com/questions/18119829
复制相似问题