Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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/android中使用regexp提取序列后的所有字符_Java_Regex - Fatal编程技术网

在java/android中使用regexp提取序列后的所有字符

在java/android中使用regexp提取序列后的所有字符,java,regex,Java,Regex,想象一下这些字符串: String s = "firstpartie_FOO_lastpartieofthestring" 或 对于regexp,我想提取第二个“\uxp”后面的字符串 我试过这个: Pattern p = Pattern.compile("(?<=_[A-Z]*_)"); Matcher m = p.matcher("lllalal_FOOBBARR_lastpartieofthestringofthedead") Pattern p=Pattern.compile(

想象一下这些字符串:

String s = "firstpartie_FOO_lastpartieofthestring"

对于regexp,我想提取第二个“\uxp”后面的字符串

我试过这个:

Pattern p = Pattern.compile("(?<=_[A-Z]*_)");
Matcher m = p.matcher("lllalal_FOOBBARR_lastpartieofthestringofthedead")

Pattern p=Pattern.compile((?试试这个,它会查找任何数量的字符,后跟一个
\uu
,然后再查找另一个数量的字符,后跟
\u
,并捕获其他所有内容:

*...*.(.*)

还有一个关于Regex101的示例:


试试这个,它会查找任何数量的字符,后跟一个
,然后再查找另一个数量的字符,后跟
,并捕获所有其他内容:

*...*.(.*)

还有一个关于Regex101的示例:


如果要修正方法,请使用捕获组捕获字符串的其余部分:

String s = "lllalal_FOOBBARR_lastpartieofthestringofthedead";
Pattern p = Pattern.compile("^[^_]*_[^_]*_(.*)", Pattern.DOTALL);
Matcher m = p.matcher(s);
if (m.find()) {
    System.out.println(m.group(1));
}
// => lastpartieofthestringofthedead

这里,
^[^.]*.
匹配字符串的开头(
^
),0+字符而不是
.
[^.]*
),
.
,再次匹配0+字符而不是
.
.
,然后将字符串的其余部分捕获到组1中(使用
(.*)

否则,使用
将其分为3部分:

String s = "lllalal_FOOBBARR_lastpartieofthestring_of_thedead";
String[] res = s.split("_", 3);
if (res.length > 2) {
    System.out.println(res[2]);
} 
// => lastpartieofthestring_of_thedead

请参见

如果要修正方法,请使用捕获组捕获字符串的其余部分:

String s = "lllalal_FOOBBARR_lastpartieofthestringofthedead";
Pattern p = Pattern.compile("^[^_]*_[^_]*_(.*)", Pattern.DOTALL);
Matcher m = p.matcher(s);
if (m.find()) {
    System.out.println(m.group(1));
}
// => lastpartieofthestringofthedead

这里,
^[^.]*.
匹配字符串的开头(
^
),0+字符而不是
.
[^.]*
),
.
,再次匹配0+字符而不是
.
.
,然后将字符串的其余部分捕获到组1中(使用
(.*)

否则,使用
将其分为3部分:

String s = "lllalal_FOOBBARR_lastpartieofthestring_of_thedead";
String[] res = s.split("_", 3);
if (res.length > 2) {
    System.out.println(res[2]);
} 
// => lastpartieofthestring_of_thedead
请看

我发现了这种方法:

Pattern p = Pattern.compile("_[A-Z]*_(.*)");
我在正则表达式研究方面取得了进展,您好;-)

解释:

…在一个下划线后,后跟任意数量(使用星号)的大写字符=>[A-Z]*,后跟另一个下划线=>[A-Z]*_

…,捕获所有字符=>(*)

在这里查找示例:

我发现这样做:

Pattern p = Pattern.compile("_[A-Z]*_(.*)");
我在正则表达式研究方面取得了进展,您好;-)

解释:

…在一个下划线后,后跟任意数量(使用星号)的大写字符=>[A-Z]*,后跟另一个下划线=>[A-Z]*_

…,捕获所有字符=>(*)


在这里找到示例:

只需使用
\u
拆分它并获取第三个数组元素只需使用
\u
拆分它并获取第三个数组元素