Regular Expression not working!
-
I have tried using this negative lookahead ".(?![a-z])" to split sentences based on the match - "dot, not followed by any characters in "a-z". It doesn't seem to work as this whole string is being considered as the pattern rather than the desired set. Please help!!
-
bq. Note: The C++ compiler transforms backslashes in strings. To include a \ in a regexp, enter it twice, i.e. \.
http://qt-project.org/doc/qt-4.8/qregexp.html#characters-and-abbreviations-for-sets-of-characters
-
I had done that(forgot to mention here) ..still no result!!
-
Can you pass your code example with a "text to be parsed"?
-
Try
@QStringList field = str.split(".(?![a-z])");@Maybe with \.
-
This way you are getting a string comparison. If you want the .split function to use a regular expression, you must pass a QRegExp:
@QStringList field = str.split(QRegExp(".(?![a-z])"));@ -
Yes I I appreciate your help, Sirop. But, I have already tried almost everything before posting here, and unfortunately nothing works. Here's my snippet :-
QString st = "HELLO HOW ARE YOU.a THANK HOW YOU.2ELLO NOT YOU.";
QStringList ql = st.split("\.(?![a-z])");
qDebug()<< ql.at(0);OUTPUT: "HELLO HOW ARE YOU.a THANK HOW YOU.2ELLO NOT YOU"
-
jazco let me try this..
-
yeah jazzco yours works with double backslash! Thanks a ton, jazzco and sirop.
-
Hi,
Double backslashes are needed because you are still writing a string, so you need escape the backslash properly in order to obtain the correct regexp. You can test and validate regular expressions for QRegExp with the regular expression example from Qt's sources.
-
Yes. I get that.