java - matcher.group(1) return no result -


    public class getprop extends activity {     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         string file_proc = readfile();         textview tv = (textview)findviewbyid(r.id.tv);         tv.settext("read file contents sdcard : \n" + file_proc);     }     public string readfile(){         bufferedreader rdr;         string proc = "";         string line;         int linenumber = 0;         try {             rdr = new bufferedreader(new filereader("/proc/cpuinfo"));                  while ((line = rdr.readline()) != null) {                 linenumber++;             matcher matcher = pattern.compile("processor: (.*)").matcher(line);             if (matcher.find()) {                 proc = matcher.group(1);             }             }                    } catch (exception e) {             e.printstacktrace();         }         return proc;             } } 

i want print 1 line /proc/cpuinfo txt file, processor: "result", result matcher.group(1). have no text in th result, problem?

this /proc/cpuinfo looks like:

processor   : 0 vendor_id   : genuineintel cpu family  : 6 model       : 42 /* etc */ 

there 2 problems regex:

  1. regular expressions case sensitive. either change processor, or use pattern.compile(..., pattern.case_insensitive).
  2. there whitespace between processor , colon. should change regex processor\\s*: (.*)

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -