qregularexpression

How QRegularExpression can be passed to Qt::MatchRegularExpression

时间秒杀一切 提交于 2021-02-11 14:18:32
问题 I am trying this sample code that I found which is really really good. I am also trying to figure out the same thing to find an item and scroll to it, but this time I wanted to match the the string which has the EXACT WORD "cat" . Example matches: cat tom cat dog and cat super cat To make it very simple I am just trying to match an exact word in a string. Take this sample code as an example: import re s= "1 tom cat" s2 = "2 thundercat" if re.search(r'\bcat\b',s2): print("There is an EXACT

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]

Regular Expression Filter for QFileDialog

前提是你 提交于 2020-01-11 13:21:49
问题 I would like to display a file open dialog that filters on a particular pattern, for example *.000 to *.999 . QFileDialog::getOpenFileNames allows you to specify discrete filters, such as *.000 , *.001 , etc. I would like to set a regular expression as a filter, in this case ^.*\.\d\d\d$ , i.e. any file name that has a three digit extension. 回答1: It can be done by adding proxy model to QFileDialog. It is explained here: Filtering in QFileDialog 回答2: ariwez pointed me into the right direction.

oracle get all matched occurrences from a column

强颜欢笑 提交于 2019-12-11 15:17:29
问题 I have a table, which has 2 columns: ID & JOB_Description(Text). I would like to write an oracle SQL to extract all substrings in the Description column which match a regular pattern. However, I have learnt how to extract matched substrings from a string with below SQL, but I have no idea to apply below SQL on all data in one go on the aforementioned table(column:JOB_Description). SQL to get all matched occurrences from a string: SELECT REGEXP_SUBSTR(JOB_Description, '(ABC|DE)([[:digit:]]){5}

How to count recurring characters at the beginning of a QString?

爷,独闯天下 提交于 2019-12-10 18:34:05
问题 Im dealing with a list of lines, and I need to count the hashes that occur at the beginning. # item 1 ## item 1, 1 ## item 1, 2 # item 2 and so on. If each line is a QString, how can I return the number of hashes occurring at the beginning of the string? QString s("### foo # bar "); int numberOfHashes = s.count("#"); // Answer should be 3, not 4 回答1: Trivially: int number_of_hashes(const QString &s) { int i, l = s.size(); for(i = 0; i < l && s[i] == '#'; ++i); return i; } In other languages

How to get substring from a string in qt?

老子叫甜甜 提交于 2019-12-05 22:15:10
问题 I have a text form: Last Name:SomeName, Day:23 ...etc From Last Name:SomeName, I would like to get Last Name, and separately SomeName. I have tried to use QRegularExpression, QRegularExpression re("(?<label>\\w+):(?<text>\\w+)"); But I am getting the result: QString label = match.captured("label") //it gives me only Name What I want is whatever text till ":" to be label, and after to be text. Any ideas? 回答1: You could use two different methods for this, based on your need: split() section()

How to get substring from a string in qt?

一曲冷凌霜 提交于 2019-12-04 05:26:37
I have a text form: Last Name:SomeName, Day:23 ...etc From Last Name:SomeName, I would like to get Last Name, and separately SomeName. I have tried to use QRegularExpression, QRegularExpression re("(?<label>\\w+):(?<text>\\w+)"); But I am getting the result: QString label = match.captured("label") //it gives me only Name What I want is whatever text till ":" to be label, and after to be text. Any ideas? lpapp You could use two different methods for this, based on your need: split() section() main.cpp #include <QString> #include <QDebug> int main() { QString myString = "Last Name:SomeName, Day

Regular Expression Filter for QFileDialog

懵懂的女人 提交于 2019-12-02 10:14:53
I would like to display a file open dialog that filters on a particular pattern, for example *.000 to *.999 . QFileDialog::getOpenFileNames allows you to specify discrete filters, such as *.000 , *.001 , etc. I would like to set a regular expression as a filter, in this case ^.*\.\d\d\d$ , i.e. any file name that has a three digit extension. ariwez It can be done by adding proxy model to QFileDialog. It is explained here: Filtering in QFileDialog ariwez pointed me into the right direction. The main thing to watch out for is to call dialog.setOption(QFileDialog::DontUseNativeDialog) before