PDA

View Full Version : CaptureText of on "AND operation" Regular Express



alancupid
23rd April 2012, 07:57
Hi,

I am using QRegExp to perform "AND" operation on the QString. I would like to get the position on found QString but always get 0.

I use positive lookahead to perform "AND" operation

QRegExp keyword_regexp("(?=.*cat)(?=.*dog)");
keyword_regexp.setPatternSyntax(QRegExp::RegExp);
QString document_text = "rooster, cat, dog, cow, cat and chicken";

int found_index = document_text.indexOf(keyword_regexp);
while (found_index >= 0)
{
int length = keyword_regexp.matchedLength();
/*do something on the length and found_index*/
found_index = document_text.indexOf(keyword_regexp, found_index + length);
}

I receive infinity loop at document_text due to indexOf(keyword_regexp); always return me 0. Provided that matchedLength() return 0 too.

It is successful if i set my keyword_regexp to "cat" only. But not an Positive lookahead ?=

I am not going to use OR operation (cat|dog) because i just only want both keywords to exist and proceed on my function.

Any advise on this?