regex

Extract the Name and Span of Regex Matched Groups

↘锁芯ラ 提交于 2021-02-11 12:03:37
问题 I have a regex that looks like: rgx = '(?P<foo>ABC)(?P<bar>DEF)?(?P<norf>HIJK)' Getting the matched string is no problem m.group(name) . However, I need to extract the name and span of the matched groups (or even just the span by name) and haven't found a way to do this. I would like to do something like: p = re.compile(p, re.IGNORECASE) m = p.match(targetstring) #then do something to set 'all' to the list of match objects for mo in all print mo.name() + '->' + mo.span() So for example the

this regular expression fail to parse all valid floating numbers

最后都变了- 提交于 2021-02-11 11:35:09
问题 I am trying to find all floating number (could be in exponential forms with -/+ prefix or not). For example, the following is the valid format: -1.2 +1.2 .2 -3 3E4 -3e5 e-5 The source of text contains several numbers separated with space or comma. I need to use regular expression to tell tell if there is any invalid number (e.g. 1.2 3.2 s3) s3 is not a valid one list every single valid number I have no idea how to get (1) done but for (2), I am using boost::regex and the following code

this regular expression fail to parse all valid floating numbers

风格不统一 提交于 2021-02-11 11:32:38
问题 I am trying to find all floating number (could be in exponential forms with -/+ prefix or not). For example, the following is the valid format: -1.2 +1.2 .2 -3 3E4 -3e5 e-5 The source of text contains several numbers separated with space or comma. I need to use regular expression to tell tell if there is any invalid number (e.g. 1.2 3.2 s3) s3 is not a valid one list every single valid number I have no idea how to get (1) done but for (2), I am using boost::regex and the following code

this regular expression fail to parse all valid floating numbers

混江龙づ霸主 提交于 2021-02-11 11:29:50
问题 I am trying to find all floating number (could be in exponential forms with -/+ prefix or not). For example, the following is the valid format: -1.2 +1.2 .2 -3 3E4 -3e5 e-5 The source of text contains several numbers separated with space or comma. I need to use regular expression to tell tell if there is any invalid number (e.g. 1.2 3.2 s3) s3 is not a valid one list every single valid number I have no idea how to get (1) done but for (2), I am using boost::regex and the following code

Regex Match decimal number between 0 to 1

梦想的初衷 提交于 2021-02-11 11:23:55
问题 I want to match a decimal number between 0 and 1 (inclusive), but the regex I wrote will match anything more than 1 too: https://regex101.com/r/mN1iT5/3 How can I solve this ^[0-1]{1}(\.[0-9]{1,2})?$ 回答1: Do: ^(?:0*(?:\.\d+)?|1(\.0*)?)$ 0*(?:\.\d+)? matches any number of 0 followed by one or digits 1(\.0*)? matches 1 followed by a decimal point, and any number of 0 s The above two are | (OR-ed) to match any one of them Demo 来源: https://stackoverflow.com/questions/40457957/regex-match-decimal

Regex Match decimal number between 0 to 1

僤鯓⒐⒋嵵緔 提交于 2021-02-11 11:18:16
问题 I want to match a decimal number between 0 and 1 (inclusive), but the regex I wrote will match anything more than 1 too: https://regex101.com/r/mN1iT5/3 How can I solve this ^[0-1]{1}(\.[0-9]{1,2})?$ 回答1: Do: ^(?:0*(?:\.\d+)?|1(\.0*)?)$ 0*(?:\.\d+)? matches any number of 0 followed by one or digits 1(\.0*)? matches 1 followed by a decimal point, and any number of 0 s The above two are | (OR-ed) to match any one of them Demo 来源: https://stackoverflow.com/questions/40457957/regex-match-decimal

Regex Match decimal number between 0 to 1

▼魔方 西西 提交于 2021-02-11 11:17:24
问题 I want to match a decimal number between 0 and 1 (inclusive), but the regex I wrote will match anything more than 1 too: https://regex101.com/r/mN1iT5/3 How can I solve this ^[0-1]{1}(\.[0-9]{1,2})?$ 回答1: Do: ^(?:0*(?:\.\d+)?|1(\.0*)?)$ 0*(?:\.\d+)? matches any number of 0 followed by one or digits 1(\.0*)? matches 1 followed by a decimal point, and any number of 0 s The above two are | (OR-ed) to match any one of them Demo 来源: https://stackoverflow.com/questions/40457957/regex-match-decimal

SQLite DB Browser: invalid operand for regexp

巧了我就是萌 提交于 2021-02-11 07:53:18
问题 I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9. This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp on column brand but failed on column revision ; For example SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$' and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms) However, if regexp is applied on different column, then I get the error

SQLite DB Browser: invalid operand for regexp

这一生的挚爱 提交于 2021-02-11 07:53:10
问题 I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9. This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp on column brand but failed on column revision ; For example SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$' and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms) However, if regexp is applied on different column, then I get the error

SQLite DB Browser: invalid operand for regexp

*爱你&永不变心* 提交于 2021-02-11 07:53:06
问题 I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9. This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp on column brand but failed on column revision ; For example SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$' and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms) However, if regexp is applied on different column, then I get the error