简体   繁体   English

与我的REGEX匹配时出错

[英]Error to match with my REGEX

May i have some help to get those string with Regex .. Here is my source code .. 我可以帮忙用正则表达式获取那些字符串吗?。这是我的源代码..

help me !!! 帮我 !!!

String t="01-21 10:56:41.161 D/RILJ    ( 2785): [rild] [2058]< VOICE_REGISTRATION_STATE {1, 271c, 0000058d, 16, null, null, null, null, null, null, null, null, null, null, null}";
String Exp= "(VOICE_REGISTRATION_STATE) .(\\d+), (\\w+), (\\w+), (\\d+),";
Pattern p = Pattern.compile("\\b"+Exp+"\\b", Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher(t);

// indicate all matches on the line //指示所有匹配项

    if (m.find()) {

  Toast.makeText(getBaseContext(),"band="+m.group(2),Toast.LENGTH_SHORT).show();
  Toast.makeText(getBaseContext(),"Lac="+m.group(3),Toast.LENGTH_SHORT).show();
  Toast.makeText(getBaseContext(),"CID="+m.group(4),Toast.LENGTH_SHORT).show();
  Toast.makeText(getBaseContext(),"Tech="+m.group(5),Toast.LENGTH_SHORT).show();
    }

The problem is only with the word boundary you added at the last. 问题仅在于您最后添加的单词边界。 Just remove it. 只需将其删除。 Because there isn't a word boundary exists between a comma ( which exists next to the number 16 ) and a space. 因为在逗号( 与数字16相邻 )和空格之间不存在单词边界。 \\b matches between a word character and a non-word character. \\b在单词字符和非单词字符之间匹配。

Pattern p = Pattern.compile("\\b" + Exp, Pattern.CASE_INSENSITIVE);

Just play with adding a word boundary at the last in here. 只需在此处最后添加一个单词边界即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM