0

下面是我的文字

 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.txt

sam.txt 谢谢

4

4 回答 4

1

遵循基于正则前瞻的正则表达式应该适合您:

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-08T09:53:01.703 回答
1

这将起作用:

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*- 零个或多个空格
  • (\\w\\)|•)- 数字或字母后跟括号或项目符号
  • \\s*- 零个或多个空格

输出:

Welcome to java programming
Oops concepts
Encapsulation
Abstraction
Inheritance
Polymorphism
于 2013-08-08T07:08:27.397 回答
0

你也可以试试这个

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 
Polymorphism
于 2013-08-08T07:16:10.250 回答
0
public class Bullet {
public static void main(String [] args){
    String str = "Welcome to java programming 1) Oops concepts a) Encapsulation A) Abstraction I) Inheritance  • Polymorphism2)sample program on java 1.Project source code sample text files • sample.txt b)sam.txt";
    String [] bullet = str.split("[0-9]\\)|[A-Z]\\)|[a-z]\\)|•|[0-9]\\.");
    for(String i:bullet){
        System.out.println(i);
    }
}

}

输出<\p>

欢迎来到 java 编程
Oops 概念
封装
抽象
继承
多态
java 示例程序
项目源代码 示例文本文件
sample.txt
sam.txt

于 2013-08-08T09:29:33.120 回答