PDA

View Full Version : How do I create QRegExp?



lni
4th December 2008, 21:10
Hi
I have a list of string separated by comman, such as

"b01350,b01351,b01352,b01353,b01354,b01355,b01356,b 01357,b01358,b01359
b01360,b01361,b01362,b01363,b01364,b01365,b01366,b 01367,b01368,b01369
b01370,b01371,b01372,b01373,b01374,b01375,b01376,b 01377,b01378,b01379
b01380,b01381,b01382,b01383,b01384,b01385,b01386,b 01387,b01388,b01389
b01390,b01391,b01392,b01393,b01394,b01395,b01396,b 01397,b01398,b01399"


I would like to convert the list using QRegExp so it become "b013[5-9][0-9]"

How do I do it?

Thanks

jpn
4th December 2008, 21:31
QStringList items = str.split(",").filter(QRegExp("b013[5-9][0-9]"));

lni
4th December 2008, 21:49
QStringList items = str.split(",").filter(QRegExp("b013[5-9][0-9]"));

Actual, I need the filter expression...

that is, I need to shorten the long list into an expression, such as "b013[5-9][0-9]", not the other way around...

calmspeaker
5th December 2008, 08:11
"^b013[5-9]\d$" or "b013[5-9]\d"
it depends on your filter purpose.

jpn
5th December 2008, 08:18
that is, I need to shorten the long list into an expression, such as "b013[5-9][0-9]", not the other way around...
Do you mean that you want to dynamically detect what's in the list and create as strict regular expression as possible based on the list contents?

lni
12th January 2009, 20:55
Do you mean that you want to dynamically detect what's in the list and create as strict regular expression as possible based on the list contents?

Yes, that is exactly what I am looking for...

aamer4yu
13th January 2009, 05:54
That would be an AI question !! u can search for pattern matching algorithms,
I dont think it will be easy to do in good time :(