Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.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 - Fatal编程技术网

Java 如何为项目符号空格数字和点编写正则表达式

Java 如何为项目符号空格数字和点编写正则表达式,java,regex,Java,Regex,我正在使用正则表达式,因为我的句子包含项目符号空格数字和点 • 1. This is sample Application • 2. This is Sample java program 正则表达式: •\\s\\d\\.\\s[A-z] Required output: This is sample Application. This is Sample java program. 它不起作用。请建议我怎么做。不要使用实际的“bullet”,而是使用unicode等价物: \u2022

我正在使用正则表达式,因为我的句子包含项目符号空格数字和点

• 1. This is sample Application
• 2. This is Sample java program
正则表达式:

•\\s\\d\\.\\s[A-z]

Required output:
This is sample Application.
This is Sample java program.

它不起作用。请建议我怎么做。

不要使用实际的“bullet”,而是使用unicode等价物:

\u2022\s\d\.\s[A-z] \u2022\s\d\.\s[A-z] 有关更多信息,请参阅和

编辑: 要拆分行(假设每行都是单独的字符串),请尝试以下操作:

String firstString = "• 1. This is sample Application"; System.out.println(firstString.split("\\u2022\\s\\d\\.\\s")[1]); String firstString=“•1.这是示例应用程序”; System.out.println(firstString.split(\\u2022\\s\\d\\.\\s“)[1]);
这是因为
String.split
会将字符串切割成一个数组,只要存在匹配项。
[1]
处理该数组中的第二项,即拆分的后半部分。

为什么
regex
?你可以用这种方式

   String str="• 1. This is sample Application";
   String newStr=str.replaceAll("\\•|\\.",""); 
   // Or str.replaceAll("\\u2022|\\.","");u2022 is unicode value of bullet 
   System.out.println(newStr);
用这个

String a="• 1. This is sample Application";
a = a.replaceAll("\\u2022(?=\\s\\d\\.\\s[A-z])",""); // this will remove the • if only the bulet have \\s\\d\\.\\s[A-z] patern after it.
System.out.println(a);

要匹配项目符号字符,需要使用unicode转义序列。但是,Unicode定义了几种项目符号样式,因此最好考虑所有这些样式:

[\u2022,\u2023,\u25E6,\u2043,\u2219]\s\d\.\s[A-z]
这应与以下项目符号样式相匹配:

  • 项目符号(•)
  • 三角形子弹(‣)
  • 白子弹(◦)
  • 连字符子弹(——)
  • 子弹操作员(∙)

参考资料:

尝试将项目符号替换为其代码点(以
\\uxxx
的形式)预期的输出应该是什么?从句子中删除项目符号空格数字、点和空格我的预期输出是这是示例应用程序。这是示例java程序。