QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");
-
QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,3}"); QRegExpValidator v(rx, 0); int pos = 0;never use first ... try to "filter" user input for write on QlineEdit the coordinate of system .... for me these world need to be VALID:
x200,5 Y900
X50
X-50
Y-1235.5 x-3and these must be UNVALID
a300 Y800
x50000
y70.00000 X60
y90 X-30 Y70
X-50,25698
Y-1235.5x-3try to use these link validator site helph
with no complete success ... because previous code for negative and positive number was not accept .... these one was accept ((C|X|Y|Z|c|x|y|z)\d{0,3}(.\d+)?\s*$) (not with double \ but with single one ... because language) ...
but work only with one only instance like x400 .... with x50 y60 and title post code not run correctly ..... -
@JonB said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^([xyuv]-?\d{1,4}([,.]\d{1,1})?)( \1)?( \1)?( \1)?$
these match only exactly the same occorence of previous ... so
these match:
x100 x100 x100
these not match (but needed)
x10 y100 u3000@gfxx
Ohhhh :( I did wonder about that, but didn't test :) That's a shame, for this particular purpose.....It's regrettable that you cannot do something about the whitespace separator which prevents you from using a
{1,4}-type thing for your pattern. The problem is that you only want to allow spaces between patterns. But how does, say,^([xyuv]-?\d{1,4}([,.]\d)? ?){1,4}$perform? The usual way with reg exs is that matches are greedy, using as much as possible e.g. when it has a choice whether to put a character in the match to its left rather than saving it for a match to the right, provided both can be done. You might find this pattern works for your inputs.
-
Hi,
Unless you are using Qt 4, please move to QRegularExpression and and QRegularExpressionValidator. QRegExp and its validator were deprecated in Qt 5.
Based on your examples, the following regexp, if used with the case insensitive option should work:
^[xy]-?\d{1,4}([,.]\d{1,3})?( [xy]-?\d{1,4}([,.]\d{1,3})?)?$ -
Hi,
Unless you are using Qt 4, please move to QRegularExpression and and QRegularExpressionValidator. QRegExp and its validator were deprecated in Qt 5.
Based on your examples, the following regexp, if used with the case insensitive option should work:
^[xy]-?\d{1,4}([,.]\d{1,3})?( [xy]-?\d{1,4}([,.]\d{1,3})?)?$@SGaist said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^[xy]-?\d{1,4}([,.]\d{1,3})?( [xy]-?\d{1,4}([,.]\d{1,3})?)?$
Thanks .... for upgrade version too .... so if need at least check 4 coordinates, based on your code ... these seems to work .... but is good too? (need one oly digit after "." ...
^[xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?)?( [xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?))$regards
-
@SGaist said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^[xy]-?\d{1,4}([,.]\d{1,3})?( [xy]-?\d{1,4}([,.]\d{1,3})?)?$
Thanks .... for upgrade version too .... so if need at least check 4 coordinates, based on your code ... these seems to work .... but is good too? (need one oly digit after "." ...
^[xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?)?( [xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?))$regards
You can simply remove the
{1,1}s. It just clutters the regex for no benefit. -
@SGaist said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^[xy]-?\d{1,4}([,.]\d{1,3})?( [xy]-?\d{1,4}([,.]\d{1,3})?)?$
Thanks .... for upgrade version too .... so if need at least check 4 coordinates, based on your code ... these seems to work .... but is good too? (need one oly digit after "." ...
^[xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?)?( [xyuv]-?\d{1,4}([,.]\d{1,1})?( [xyuv]-?\d{1,4}([,.]\d{1,1})?))$regards
-
@gfxx
It's up to you what your rules are, but why do you now have both[xyuv]and[xyzc]? You are introducing new restrictions, and your reg ex is getting more & more complicated! -
@JonB sorry zc is an error becuse previuos name of coordinates .... correct just now. .... simply need to have 4 item of coordinates no more but can be less ....
-
for me these world need to be VALID:
x200,5 Y900 u900 v-10.9
X50
X-50
Y-1235.5 x-3and these must be UNVALID
a300 Y800 u600 v200 x3000 (because 5 coord.)
x50000
y70.00000 X60
y90 X-30 Y70
X-50,25698
Y-1235.5x-3the same as previous but with 4 cood. The code suggested work ... only ask if possible make it better .... if tomorrow need to check 8 coord. in one only time .... the code used become a very long string (more bigger more error) .... only these ... thanks
-
for me these world need to be VALID:
x200,5 Y900 u900 v-10.9
X50
X-50
Y-1235.5 x-3and these must be UNVALID
a300 Y800 u600 v200 x3000 (because 5 coord.)
x50000
y70.00000 X60
y90 X-30 Y70
X-50,25698
Y-1235.5x-3the same as previous but with 4 cood. The code suggested work ... only ask if possible make it better .... if tomorrow need to check 8 coord. in one only time .... the code used become a very long string (more bigger more error) .... only these ... thanks
@gfxx
Leaving aside the fact that you change your examples/code as we go along, e.g. introduction of[xyuv], it's hard to keep up.To keep it manageable, you need to use regular expression back references. This will allow you to insert the "complicated" pattern (for each individual space-separated entry) just once, and then use again a number of times without having to repeat it. You can easily change between, say, 2 occurrences and 4 occurrences.
This is done by surrounding that pattern segment in parentheses (
(...)) and then using\digit (\1) to call it back. Consider:([a-zA-Z]+) \1 \1This means 3 words, with a space between each (not at beginning or end).
So your pattern for 4 will be something like
^([xyuv]-?\d{1,4}([,.]\d{1,1})?)( \1)?( \1)?( \1)?$A lot easier, right?!
I have not verified that Qt
QRegularExpressionaccepts these back references, though I am expecting it to. You should test on a small example and then use it if it works. -
@gfxx
Leaving aside the fact that you change your examples/code as we go along, e.g. introduction of[xyuv], it's hard to keep up.To keep it manageable, you need to use regular expression back references. This will allow you to insert the "complicated" pattern (for each individual space-separated entry) just once, and then use again a number of times without having to repeat it. You can easily change between, say, 2 occurrences and 4 occurrences.
This is done by surrounding that pattern segment in parentheses (
(...)) and then using\digit (\1) to call it back. Consider:([a-zA-Z]+) \1 \1This means 3 words, with a space between each (not at beginning or end).
So your pattern for 4 will be something like
^([xyuv]-?\d{1,4}([,.]\d{1,1})?)( \1)?( \1)?( \1)?$A lot easier, right?!
I have not verified that Qt
QRegularExpressionaccepts these back references, though I am expecting it to. You should test on a small example and then use it if it works.@JonB said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^([xyuv]-?\d{1,4}([,.]\d{1,1})?)( \1)?( \1)?( \1)?$
these match only exactly the same occorence of previous ... so
these match:
x100 x100 x100
these not match (but needed)
x10 y100 u3000 -
@JonB said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
^([xyuv]-?\d{1,4}([,.]\d{1,1})?)( \1)?( \1)?( \1)?$
these match only exactly the same occorence of previous ... so
these match:
x100 x100 x100
these not match (but needed)
x10 y100 u3000@gfxx
Ohhhh :( I did wonder about that, but didn't test :) That's a shame, for this particular purpose.....It's regrettable that you cannot do something about the whitespace separator which prevents you from using a
{1,4}-type thing for your pattern. The problem is that you only want to allow spaces between patterns. But how does, say,^([xyuv]-?\d{1,4}([,.]\d)? ?){1,4}$perform? The usual way with reg exs is that matches are greedy, using as much as possible e.g. when it has a choice whether to put a character in the match to its left rather than saving it for a match to the right, provided both can be done. You might find this pattern works for your inputs.
-
@gfxx
Ohhhh :( I did wonder about that, but didn't test :) That's a shame, for this particular purpose.....It's regrettable that you cannot do something about the whitespace separator which prevents you from using a
{1,4}-type thing for your pattern. The problem is that you only want to allow spaces between patterns. But how does, say,^([xyuv]-?\d{1,4}([,.]\d)? ?){1,4}$perform? The usual way with reg exs is that matches are greedy, using as much as possible e.g. when it has a choice whether to put a character in the match to its left rather than saving it for a match to the right, provided both can be done. You might find this pattern works for your inputs.
@JonB said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
Ohhhh :( I did wonder about that, but didn't test :) That's a shame, for this particular purpose.....
It's regrettable that you cannot do something about the whitespace separator which prevents you from using a {1,4}-type thing for your pattern. The problem is that you only want to allow spaces between patterns.real thanks .... because try a lot of combination ... think anly not test was these:
^([xyuv]-?\d{1,4}([,.]\d)? ?){1,4}$
where "? (spaces) ?" make the differences .... but exactly where find some instructions and "example" about these "markup" (sorry but not know how can call these sort of languages regexp)?
-
G gfxx has marked this topic as solved on
-
@JonB said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
Ohhhh :( I did wonder about that, but didn't test :) That's a shame, for this particular purpose.....
It's regrettable that you cannot do something about the whitespace separator which prevents you from using a {1,4}-type thing for your pattern. The problem is that you only want to allow spaces between patterns.real thanks .... because try a lot of combination ... think anly not test was these:
^([xyuv]-?\d{1,4}([,.]\d)? ?){1,4}$
where "? (spaces) ?" make the differences .... but exactly where find some instructions and "example" about these "markup" (sorry but not know how can call these sort of languages regexp)?
@gfxx
My solution is a bit "cheaty" or "lucky". Because the space-separator has to be made optional via?(that is the space-?), so as to allow for it not being at the end (or beginning) or the whole pattern, my pattern has a "danger" of allowing the stuff before it to "run into" the stuff after it, by choosing to match the space zero times for the?. But, as I said, for your inputs it may not be able to do that, and can only match the way we want. Which seems to be the case.As for where/how to learn regular expressions: I have done them all my lifetime :) It's an art as much as a science. There are various reference pages all over the web --- the Qt docs for regular expressions may even refer you to one. And play with things at https://regex101.com/.
-
@gfxx
My solution is a bit "cheaty" or "lucky". Because the space-separator has to be made optional via?(that is the space-?), so as to allow for it not being at the end (or beginning) or the whole pattern, my pattern has a "danger" of allowing the stuff before it to "run into" the stuff after it, by choosing to match the space zero times for the?. But, as I said, for your inputs it may not be able to do that, and can only match the way we want. Which seems to be the case.As for where/how to learn regular expressions: I have done them all my lifetime :) It's an art as much as a science. There are various reference pages all over the web --- the Qt docs for regular expressions may even refer you to one. And play with things at https://regex101.com/.
-
@JonB "cheaty" or "lucky" not important if work as work .... maybe you are an artist in these things and not a scientist .... but is really important?
Thanks a lot.
@gfxx said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
but is really important?
Sadly, yes. I don't mean to burst our bubble, but I think it will accept this:
x10y100Note that there is no space before the
y. You may not be happy with this.... -
@gfxx said in QRegExp rx("[((X|Y|x|y)\\d{0,3}(\\.\\d+)?\\S$)]{0,1}");:
but is really important?
Sadly, yes. I don't mean to burst our bubble, but I think it will accept this:
x10y100Note that there is no space before the
y. You may not be happy with this....