Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED]QRegExp allow only one white space between strings
jpincz last edited by
Hi, guys maybe you can help with this i really tried but it is very difficult to undertand
i read from here :https://qt-project.org/doc/qt-4.8/qregexp.html
if you have a more comprehensive link would be grateful.
A definition for this example W == any string that does not contain a white space.
I'm trying to write the following regular expression
W[space] - - - - - - not allowed (match==false)
[space]W - - - - - - not allowed (match==false)
W[space]W - - - - - ALLOWED (match==true)
W[space][space]W - - - not allowed (match==false)
W[space]W [space]W - - - ALLOWED (match==true)
W[space]W [space][space]W - - - not allowed (match==false)
W[space]W [space]W[space] - - - not allowed (match==false)
[space]W[space]W [space]W - - - not allowed (match==false)
still macth this case WORD[SPACE] but works for me , thanks to ChrisW67
Hi and welcome to devnet,
Can you provide a concrete string and QRegExp code example ?
jpincz last edited by
first sorry for my english and thanks for you reply..
i read this documentation:
and it si very hard to undertand still i tried , dont put code as example bcz dont want someone answer base on them
if u have another link with differents or more examples i will be gratefull
the more closer i get was with this:
but what i need have to match with strings made of word characters and NONword characters(obv excluiding " ") and can have only one space between them but not a first or last as i detailed in my first post
example of a match:
@QString s="lucas" + " " + "tornado" + " " + "n°1995" + " " + "12-12-12" + " " + "erkntowertn";@
examples of a non match:
@QString s= "lucas" + " ";
QString s= " " + "lucas";
QString s= "lucas" + " " + " " + "tornado";@
i am gonna use it as this on qline edit:
@ QRegExp rx("MAGIC");
ui->lineEditDesc->setValidator(new QRegExpValidator(rx, ui->lineEditDesc));@
for now i use this
@void NewProduct::on_lineEditDesc_textEdited(const QString &arg1)
ui-> lineEditDesc-> setText(arg1.simplified());
but i that way the user can not put a space on the end of the word to start another word , he has to write all together and then put the spaces
ChrisW67 last edited by
I would think something like:
QRegExp rx("^\S+(\s\S+)+$"); // if there must be two or more words
QRegExp rx("^\S+(\s\S+)*$"); // if only one word will do
would match lines starting and ending with a "word" and containing only single spaces and words in between.
koahnig last edited by
You might find the "RegExp example":http://qt-project.org/doc/qt-4.8/tools-regexp.html quite useful for trial and error with different expressions.