Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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,下面是我的绳子 {" 3/4", "ERW", "A53-A", "STEEL", "PIPE", "STD", "BLK", "PE"} 我需要匹配这个字符串使用正则表达式,请帮助我实现这一点 我尝试在下面的代码片段中实现这一点,但它只匹配了6个字符串,我可以使用它来匹配 String pattern = "\\s*,\\s*"; String[] sourceValues= listTwo.get(1).toString().split(pattern); 我无法使用此模式匹配第一个和

下面是我的绳子

{" 3/4", "ERW", "A53-A", "STEEL", "PIPE", "STD", "BLK", "PE"} 
我需要匹配这个字符串使用正则表达式,请帮助我实现这一点

我尝试在下面的代码片段中实现这一点,但它只匹配了6个字符串,我可以使用它来匹配

String pattern = "\\s*,\\s*";
String[] sourceValues= listTwo.get(1).toString().split(pattern);
我无法使用此模式匹配第一个和最后一个字符串

请帮助我实现这一点,我需要匹配所有8个字符串

谢谢, Sandesh P

您可以尝试:

这将捕获双引号之间的内容,而在第1组中没有一个前导空格。现在你有8个字符串而不是6个

List<String> allMatches = new ArrayList<String>();
Matcher m = Pattern.compile("\" ?([^\"]+)\"").matcher("{\" 3/4\", \"ERW\", \"A53-A\", \"STEEL\", \"PIPE\", \"STD\", \"BLK\", \"PE\"}");
while (m.find()) {
    allMatches.add(m.group(1));
}

请注意,您期望的输出是什么请参考下面的链接了解期望输出字符串输入的详细信息={\3/4\,\ERW\,\A53-A\,\STEEL\,\PIPE\,\STD\,\BLK\,\PE\;字符串模式=\\s*,\\s*;String[]sourceValues=input.splitpattern;System.out.printlnArrays.asListSourceValue;输出:[{3/4,ERW,A53-A,钢,管道,标准,黑色,聚乙烯]。在我看来,所有的字符串都是匹配的