2

I have a QString that I have replaced "=" and"," with " ". Now I would like to write a regular expression that would remove every occurrence of a certain string followed immediately by parenthesis containing a 1 to 2 character long number. For Example: "mat(1) = 5, mat(2) = 4, mat(3) = 8" would become "5 4 8"

So this is what I have so far:

text = text.replace("=", " "); 
text = text.replace(",", " "); 
text = text.remove( QRegExp( "mat\([0-9]{1,2}\)" ) );

The regular expression is not correct, how can I fix it to do what i want? Thanks!

1 Answer 1

7

You need to escape your backslashes for C++ string literals:

text = text.remove( QRegExp( "mat\\([0-9]{1,2}\\)" ) );
Sign up to request clarification or add additional context in comments.

2 Comments

this does not work for me. the original backslashes I have are for that purpose. Did you try this and it worked?
Just realized I was wrong! This did work, I just had to make sure to specify that it was not case insensitive to catch MAT at well. THANKS!

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.