PDA

View Full Version : QRegExp independent subexpressions



Nik8768
17th April 2010, 18:17
this "(?<=exp)" dose not work with QRegExp:

e.g.


QRegExp rx("((?<=a)b)");
rx.indexIn("cx ab ab xv");
QStringList list = rx.capturedTexts();

after executing that code, "list" is empty which is wrong.

any idea?

Nik8768
18th April 2010, 12:38
anyone??
this problem is really bugging me.. still couldn't find out why QT dosent recognize "(?<=exp)"

Nik8768
18th April 2010, 12:49
someone delete this thread from here.. I'm posting it in "Qt Programming" sub-forum

wysota
18th April 2010, 13:03
No, you are posting here because the answer to your question is in the documentation.

Nik8768
18th April 2010, 13:19
No, you are posting here because the answer to your question is in the documentation.

from qt docs: ""independent" subexpressions and conditional expressions are not supported."
ok I'm starting new thread..

Nik8768
18th April 2010, 13:23
since QT dose not support "independent" subexpressions in regular expression like : "(?<=exp)"
so are there any ways around it?

e.g:

QRegExp rx("((?<=a)b)");
rx.indexIn("cx ab ab xv");
QStringList list = rx.capturedTexts();

wysota
18th April 2010, 13:29
What is the exact effect you wish to obtain?

Also, please don't spawn multiple threads on the same or similar subject. Instead continue the old thread. Threads merged.

Nik8768
18th April 2010, 13:47
What is the exact effect you wish to obtain?

Also, please don't spawn multiple threads on the same or similar subject. Instead continue the old thread. Threads merged.

alright..
the thing is that:
suppose we have this string:
"blablabla : 234 : 23k 5j245 :345"
I need to get this list: "234", " 23k 5j245", "345"
(or we can say all words between ":" should be separated and last word may not end with ":")
this regular expression works fine: (?<=:\s*)[^:]*(?=(:| ))

so how do I not use "(?<=exp)" there?

Nik8768
18th April 2010, 14:01
nvm..
solved by using these two regular expression together:
:[^:]*(?=(:| )) and then applying to each capture with [^: ].*$

wysota
18th April 2010, 23:28
Hmm... wouldn't this be simpler?


QString myWeirdString = "...";
QStringList components = myWeirdString.split(":"); // or QRegExp("\s*:\s*") if you want to ignore white spaces