qregexp

Qt QLineEdit Input Validation

*爱你&永不变心* 提交于 2021-02-05 06:52:30
问题 How would one set an input validator on a QLineEdit such that it restricts it to a valid IP address? i.e. x.x.x.x where x must be between 0 and 255.and x can not be empty 回答1: You are looking for QRegExp and QValidator, to validate an IPv4 use this expresion: \b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-‌​9]|[01]?[0-9][0-9]?)‌​\.(25[0-5]|2[0-4][0-‌​9]|[01]?[0-9][0-9]?)‌​\.(25[0-5]|2[0-4][0-‌​9]|[01]?[0-9][0-9]?)‌​\b Example: QRegExp ipREX("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]

QRegExp and single-quoted text for QSyntaxHighlighter

核能气质少年 提交于 2020-01-30 10:02:35
问题 What would the QRegExp pattern be for capturing single quoted text for QSyntaxHighlighter? The matches should include the quotes, because I am building a sql code editor. Test Pattern string1 = 'test' and string2 = 'ajsijd' So far I have tried: QRegExp("\'.*\'") I got it working on this regex tester: https://regex101.com/r/eq7G1v/2 but when I try to use that regex in python its not working probably because I need to escape a character? self.highlightingRules.append((QRegExp("(['])(?:(?=(\\?))

QString: Remove first occurance of regular expression

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-16 03:58:47
问题 QString has a method remove that takes a QRegExp . It removes every occurrence of the regular expression. Is there a way to remove only the first occurrence of the regular expression? Answer to QString replace only first occurrence doesn't help. See comment from Akiva there. 回答1: You can use next code: QString message = "This is the original text"; QRegExp rx = QRegExp("is|he", Qt::CaseInsensitive); if (message.contains(rx)){ message = message.remove(rx.pos(0), rx.cap(0).size()); } The final

QRegExp and double-quoted text for QSyntaxHighlighter

喜你入骨 提交于 2020-01-14 06:05:44
问题 What would the QRegExp pattern be for capturing quoted text for QSyntaxHighlighter? Test Pattern "one" or "two" or "three" So far I have tried: QRegExp rx("\\0042.*\\0042"); QRegExp rx("(\\0042).*?\\1"); The last pattern succeeds on regexpal.com but not with the QRegExp class. 回答1: EDIT: If you check out the Syntax Highlighter Example, already has this one in there. http://qt-project.org/doc/qt-4.8/richtext-syntaxhighlighter-highlighter-cpp.html quotationFormat.setForeground(Qt::darkGreen);

Is there any difference between QRegularExpression and QRegExp?

假如想象 提交于 2019-12-18 18:34:28
问题 I see there is a new class for regular expressions - QRegularExpression . Is it just a typedef for QRegExp, or a new class, or what? And why do we need it, we already have QRegExp? 回答1: Ok, after some more digging into the docs, I found it really is a new class, it has improvements, but it is only available in Qt5, so you can't use it if you want to compile on both Qt4 and Qt5: Notes for QRegExp Users The QRegularExpression class introduced in Qt 5 is a big improvement upon QRegExp, in terms

QRegExp to extract string between a tag in html

风流意气都作罢 提交于 2019-12-11 05:09:46
问题 The situation is tricky as I do not have access to webkits on qt module, I am forced to parse an HTML file using QRegExp: The file contains strings which I need to extract which are well placed between li tags. If I write a QRegExp QRegExp ("[^</li>]([a-zA-Z0-9_./]+)"); I could Extract all the strings between li tag. But all I need are: Pg_1_qds_Bin_Indicator_2 Pg_1_qds_Bin_Indicator_3 Pg_1_qds_Ana_Indicator_1 and all the names similar to this enclosed between li someother names include which