Thread overview | |||||
---|---|---|---|---|---|
|
June 23, 2018 Redundant "g" flag for regex? | ||||
---|---|---|---|---|
| ||||
I get the same output with or without "g" flag at line 6: https://run.dlang.io/is/9n7iz6 So I don't understand when I have to use "g" flag. |
June 23, 2018 Re: Redundant "g" flag for regex? | ||||
---|---|---|---|---|
| ||||
Posted in reply to biocyberman | On Saturday, 23 June 2018 at 12:17:08 UTC, biocyberman wrote: > > I get the same output with or without "g" flag at line 6: > https://run.dlang.io/is/9n7iz6 > > So I don't understand when I have to use "g" flag. My bet is that Regex results in D are lazy so "g" doesn't make sense in this context however I'm able to see an effect with "match": match("12000 + 42100 = 54100", regex(r"(?<=\d)(?=(\d\d\d)+\b)", "")).writeln; match("12000 + 42100 = 54100", regex(r"(?<=\d)(?=(\d\d\d)+\b)", "g")).writeln; matchFirst would be like without "g" matchAll would be like with "g" |
June 23, 2018 Re: Redundant "g" flag for regex? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Saturday, 23 June 2018 at 13:45:32 UTC, Basile B. wrote: > On Saturday, 23 June 2018 at 12:17:08 UTC, biocyberman wrote: >> >> I get the same output with or without "g" flag at line 6: >> https://run.dlang.io/is/9n7iz6 >> >> So I don't understand when I have to use "g" flag. > > My bet is that Regex results in D are lazy so "g" doesn't make sense in this context however I'm able to see an effect with "match": > > match("12000 + 42100 = 54100", regex(r"(?<=\d)(?=(\d\d\d)+\b)", "")).writeln; > match("12000 + 42100 = 54100", regex(r"(?<=\d)(?=(\d\d\d)+\b)", "g")).writeln; > > matchFirst would be like without "g" > matchAll would be like with "g" I should have read the doc more thoroughly: https://dlang.org/phobos/std_regex.html#match >Delegating the kind of operation to "g" flag is soon to be phased out along with the ability to choose the exact matching scheme. So case closed for me |
Copyright © 1999-2021 by the D Language Foundation