0

I would like to write simple regexp with Qt QRegExp

I want to fetch all substring of a Qstring with table(i, d), without the quotes, with i "hard written" and d representing any integer. And then using cap, to retrieve value for d. I propose

 qREgExp reg ( "table(i,\\s*(\\d+)\\s*)") ;

I cherrish the hope that then

 reg.cap(2)

gives me the d in question here.

How would you put it?

Ωmega
  • 42,614
  • 34
  • 134
  • 203
kiriloff
  • 25,609
  • 37
  • 148
  • 229

1 Answers1

2

Try to use

qREgExp reg ( "\\btable\\(i,\\s*(\\d+)\\s*\\)" );

with

reg.cap(1) 
Ωmega
  • 42,614
  • 34
  • 134
  • 203
  • 1
    Exactly. The parenthesis on the table "call" aren't escaped, and then they are parsed as operators of the regular expression. Escaping them makes them part of the text to match. – Spidey Oct 17 '12 at 13:19
  • @Spidey thanks!! then `"\\btable\\(i,\\s*(\\.+)\\s*\\)"` should match data(i,1), isnt it ? it is not. – kiriloff Oct 17 '12 at 14:02
  • @Spidey maybe this is better `"\\btable\\(i,\\s*(.+)\\s*\\)"` !? this is matching, but i cannot retrieve the . with cap – kiriloff Oct 17 '12 at 14:03
  • Try "\\btable\\(i,([^\\)]+)\\)". – Spidey Oct 17 '12 at 15:40