qt4 - Get strings from QRegex pattern (return as Stringlist / arrays) -


example:

qfile controller_selected_file(loaded_file);  if (controller_selected_file.open(qiodevice::readonly)) {     // grab data     qtextstream in(&controller_selected_file);      // read     qstring read_data = in.readall();      // regex match function "public function something()"     qregexp reg("(static|public|final)(.*)function(.*)[a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]", qt::caseinsensitive);      // read regex , file     reg.indexin(read_data);      qstringlist data_render = reg.capturedtexts();      qdebug() << data_render;      qdebug() << data_render[0];     qdebug() << data_render[1];     qdebug() << data_render[3];      // ... } 

i want grab in file appears public function somefunction() , public function something($a,$b = "example") appears in file, receives full of file string or receive public on first array.

so want grab data appears arrays:

public function somefunction().

so in simple, parse function names in file.

full function of regex in qregexp expression:

(static|public|final)(.*)function(.*)[a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff] 

edit: want grab appears in strings on php file. problems appears when receive strings in file instead strings defined regular expression.

thank respect!

if understand question right, think need modify regex qregexp reg( "((static|public|final).*function.*\([\\w\\s,]*\))" );

with above regexp, can match static function newfunc( int gen_x, float a_b_c )

qfile controller_selected_file(loaded_file);  if (controller_selected_file.open(qiodevice::readonly)) {     // grab data     qtextstream in(&controller_selected_file);      // read     qstring read_data = in.readall();      // regex match function "public function something()"     qregexp reg( "((static|public|final).*function.*\([\\w\\s,]*\))" );      // read regex , file     qdebug() << reg.indexin( read_data );     qdebug() << reg.cap( 1 );     // ... } 

say read_data contains following text

"this text: static function newfunc( int generic, float special ) , contains other text, not important" 

then output be

19 "static function newfunc( int generic, float special )" 

i hope want.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -