0

What I am looking to do:

  1. Find all files that are of the type autogen_X.c, autogen_X.h or Project name.c (in the src folder on the root level)
  2. Print them out

The QRegExp I have is: \nsrc[^\n]*

The text that I have is:

####################################################################    
# Files                                                            #
####################################################################

C_SRC +=  \
src/autogen_init.c \
src/autogen_init.h \
src/Project name.c \
lib/src/acmp.c \
lib/src/adc.c \
lib/src/aes.c \`


s_SRC +=  \
Device/Source/G++/startup_32.s


S_SRC += 

The code I have

  QRegExp linkRx = QRegExp("src/[^\\n]*");
  linkRx.indexIn(content);

  foreach (QString match, linkRx.capturedTexts())
  {
    qDebug() << match;
  }

The output I am getting

"src/autogen_init.c \" 

Should this not match all files that start with just src/?

Arnab Datta
  • 5,356
  • 10
  • 41
  • 67

1 Answers1

0

You should preprocess the file, it will simplify the task a lot:

text.replace("\\\n", " ");

(\ at the end of a line means concatenate with the next line).

Then, you can capture what you want with the regexp (src/[^ ]*). Note the parenthesis, in order to capture text.

Also, this regexp will capture src/adc.c in lib/src/adc.c. To fix that, you can use a regexp which excludes certain characters from being before "src", example: ([^a-zA-Z_0-9/]src/[^ ]*).

Note that it cannot match filenames with spaces in it. By the way, in a normal qmake file, names with spaces are put between quotation marks. You cannot parse correctly quotations marks only with regexps.

Synxis
  • 9,236
  • 2
  • 42
  • 64