regex - Qt5 Qregexp : why my pattern can't work? -


i problem when open text file, can't matched string. test pattern: .* can either nothing. i'm sure text file can read, , pattern can accepted in grep. thank you.

qlist<nmap_result> ans; qfile file(path); if(!file.open(qfile::readonly|qfile::text)) {     exit(1); }  qstring text = file.readall(); qregexp reg(qregexp::escape(".*"));  reg.indexin(text); qdebug()<<reg.capturedtexts().join("|")<<endl<<reg.capturecount()<<endl; 

sorry, should not use escape. when change this:

qstring text = file.readall(); qdebug()<<text<<endl; qregexp reg("[0-9]");  //reg.indexin(text);          //first bind expr test reg.exactmatch(text);       //second bind expr test qdebug()<<reg.capturedtexts().join("|!!!!!|")<<endl<<reg.capturecount()<<endl; 

i use

reg.indexin(text); 

to bind string regexp, return number,but when use next expr

reg.exeacmatch(text); 

i nothing.

why call qregexp::escape method ?

try instead:

 qregexp reg(".*"); 

calling qregexp::escape, regular expression becomes similar string: "\\.\\*". string indicates want match dot immediatly followed star. not intented use here: match 0 or more characters (.*).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -