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

Java中的子字符串,带有循环子字符串

Java中的子字符串,带有循环子字符串,java,parsing,substring,Java,Parsing,Substring,我有这个字符串: file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/ 我的目标是在这种情况下只解析字符串AAA,但我将面对其他类似的字符串,其中AAA不是字符串,而是不同的东西。 是否有一种方法可以解决这个问题,例如基于重复字符串webapproot?使用模式类使用regex来提取AAA String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/

我有这个字符串:

file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/
我的目标是在这种情况下只解析字符串AAA,但我将面对其他类似的字符串,其中AAA不是字符串,而是不同的东西。
是否有一种方法可以解决这个问题,例如基于重复字符串webapproot?

使用
模式
类使用regex来提取
AAA

String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/";
Pattern p = Pattern.compile("/projects/(.*?)/webapproot/");
Matcher m = p.matcher(s);
if (m.find()) 
  System.out.println(m.group(1)); // => result "AAA"

使用正则表达式使用
模式
类来提取
AAA

String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/";
Pattern p = Pattern.compile("/projects/(.*?)/webapproot/");
Matcher m = p.matcher(s);
if (m.find()) 
  System.out.println(m.group(1)); // => result "AAA"

使用正则表达式使用
模式
类来提取
AAA

String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/";
Pattern p = Pattern.compile("/projects/(.*?)/webapproot/");
Matcher m = p.matcher(s);
if (m.find()) 
  System.out.println(m.group(1)); // => result "AAA"

使用正则表达式使用
模式
类来提取
AAA

String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/";
Pattern p = Pattern.compile("/projects/(.*?)/webapproot/");
Matcher m = p.matcher(s);
if (m.find()) 
  System.out.println(m.group(1)); // => result "AAA"


字符串的其余部分呢?不需要,我只需要一个正则表达式。如果模式确实是“/XXX/webapproot/”且“XXX”是变量字符串,那么您可以使用正则表达式。请显示预期输入的完整集。@user840718我的意思是,字符串其余部分的模式是什么?这是否也会改变,或者是完全相同的模式,只有AAA更改为其他内容?字符串的其余部分呢?不需要,我只需要AAA。如果模式确实是“/XXX/webapprot/”且“XXX”是变量字符串,您可以使用正则表达式。请显示预期输入的完整集。@user840718我的意思是,字符串其余部分的模式是什么?这是否也会改变,或者是完全相同的模式,只有AAA更改为其他内容?字符串的其余部分呢?不需要,我只需要AAA。如果模式确实是“/XXX/webapprot/”且“XXX”是变量字符串,您可以使用正则表达式。请显示预期输入的完整集。@user840718我的意思是,字符串其余部分的模式是什么?这是否也会改变,或者是完全相同的模式,只有AAA更改为其他内容?字符串的其余部分呢?不需要,我只需要AAA。如果模式确实是“/XXX/webapprot/”且“XXX”是变量字符串,您可以使用正则表达式。请显示预期输入的完整集。@user840718我的意思是,字符串其余部分的模式是什么?这是否也会改变,或者是完全相同的模式,只有AAA改变为其他模式?