Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.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
Android和regex读取子字符串_Android_Regex - Fatal编程技术网

Android和regex读取子字符串

Android和regex读取子字符串,android,regex,Android,Regex,我试图在Android应用程序中使用正则表达式来读取子字符串。我正在使用模式和匹配器,但我不知道怎么做 我的输入字符串是:javascript:submitFormdocument.voip_call_log,30,0,'xxxxx',0,; 其中xxxxx是可变位数 如何使用Pattern和Matcher读取“xxxxx”?如果您始终使用该格式,则使用split、方法和访问您喜欢的值可能会更容易 或者,您也可以尝试这样做: String str = ...; Pattern p = Patte

我试图在Android应用程序中使用正则表达式来读取子字符串。我正在使用模式和匹配器,但我不知道怎么做

我的输入字符串是:javascript:submitFormdocument.voip_call_log,30,0,'xxxxx',0,; 其中xxxxx是可变位数


如何使用Pattern和Matcher读取“xxxxx”?

如果您始终使用该格式,则使用split、方法和访问您喜欢的值可能会更容易

或者,您也可以尝试这样做:

String str = ...;
Pattern p = Pattern.compile("(\\d{3,})");
Matcher m = p.matcher(str);
while(m.find())
{
     System.out.println(m.group(1));
}
试试这个:

String s = "javascript:submitForm(document.voip_call_log,30,0,'1999','',0,'');";
Pattern pattern = Pattern.compile("javascript:submitForm\\([^,]+,\\d*,\\d*,'(\\d+)','\\d*'");
Matcher m = pattern.matcher(s);
if(m.find( )) {
    System.out.println(m.group(1));
}
这遵循问题描述中输入字符串的模式。您可以从中找到正则表达式的解释。只需用单斜杠\而不是双斜杠输入正则表达式即可。\\

我不是正则表达式专家,但这一条应该适合您:

String input = "javascript:submitForm(document.voip_call_log,30,0,'5555','',0,'');";
Pattern pattern = Pattern.compile(",'(\\d*)',");
Matcher matcher = pattern.matcher(input);
matcher.find();
String out = matcher.group(1);
System.out.println(out);
证明