Пример:
QFile controller_selected_file(loaded_file);
if (controller_selected_file.open(QIODevice::ReadOnly))
{
// grab a data
QTextStream in(&controller_selected_file);
// read all
QString read_data = in.readAll();
// Regex for 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 by regex and 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];
// ...
}
Я хочу захватить в файл все, где появляется public function somefunction()
, и еще одно public function something($a,$b = "example")
, где появляется в файле, но я получаю только полную строку файла или получаю только public
в первом массиве.
Итак, я хочу захватить все данные, которые отображаются в виде массивов:
public function somefunction()
.
Таким образом, просто проанализируйте все имена функций в файле.
Полная функция регулярного выражения в выражении QRegexp:
(static|public|final)(.*)function(.*)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]
Изменить: я хочу, чтобы все отображалось в строках в файле PHP. Проблемы возникают, когда вы получаете все строки в файле вместо строк, определенных с помощью регулярного выражения.
Спасибо за уважение!