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?

1 Answer 1

2

Try to use

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

with

reg.cap(1) 
Sign up to request clarification or add additional context in comments.

4 Comments

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 thanks!! then "\\btable\\(i,\\s*(\\.+)\\s*\\)" should match data(i,1), isnt it ? it is not.
@Spidey maybe this is better "\\btable\\(i,\\s*(.+)\\s*\\)" !? this is matching, but i cannot retrieve the . with cap
Try "\\btable\(i,([^\)]+)\)".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.