0

I am trying to search the following pattern : <b>.+</b>$

But this pattern must not contain a <b> tag.

Given the following example: abba <b>acba</b> <b>adba</b>

If I use the previous pattern, the result is : <b>acba</b> <b>adba</b>

But the good result, which I want is : <b>adba</b>

Because I want disallow a <b> tag between the two <b> and </b> border tags.

So, how can I do that?

I use QRegExp and I code in c++ language.

Thank you in advance for your help,

Floréal.

Floréal C
  • 98
  • 1
  • 7
  • Your example does only contain two open/close pairs. Not one open/close pair within another open/close pair. Did I misunterstand something or is there something wrong with the example? – Bowdzone Dec 10 '14 at 09:20
  • Mandatory read: http://stackoverflow.com/a/1732454/214671 – Matteo Italia Dec 10 '14 at 12:02

2 Answers2

2

See : QRegExp::setMinimal ( bool minimal )

Just set the QRegExp setMinimal property to true. E.g. :

QRegExp regExp;
regExp.setMiminal(true);
// use your reg exp

This will resolve your query.

Pratham
  • 1,522
  • 1
  • 18
  • 33
0

You can use a not flag:

QRegExp rx("\\<b\\>[^\\<b\\>]+\\</b\\>");
Sebastian Lange
  • 3,879
  • 1
  • 19
  • 38