Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
July 15, 2013 Types of regex | ||||
---|---|---|---|---|
| ||||
Hello, I read the library reference for regex. I really miss python's equivalent of finditer. Sometimes matching is not on purpose and one will want to match all the occurences to iterate over it since it is much more regarding concerning the orders and repetitions. my code : ----------------------------------------------------------------------------- version(Tango) extern (C) int printf(char *, ...); import std.stdio; import std.regex; import std.file; import std.format; int main(char[][] args) { string fl = readText("testregexd.txt"); auto m = match(fl, regex(`(<n=(?:hello|goodbye))*`,"g")); auto c = m.captures; writeln(c); return 0; } --------------------------------------------------------------------------- Content of testregexd.txt: ---------------------------------------------------------------------------- <n=hello <n=goodbye ---------------------------------------------------------------------------- Any way to workaround ? Thanks ! Larry |
July 15, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to Larry | On 2013-07-15, 11:32, Larry wrote: > Hello, > > I read the library reference for regex. > > I really miss python's equivalent of finditer. > > Sometimes matching is not on purpose and one will want to match all the occurences to iterate over it since it is much more regarding concerning the orders and repetitions. > > > my code : > ----------------------------------------------------------------------------- > version(Tango) extern (C) int printf(char *, ...); > > import std.stdio; > import std.regex; > import std.file; > import std.format; > > int main(char[][] args) > { > string fl = readText("testregexd.txt"); > > auto m = match(fl, regex(`(<n=(?:hello|goodbye))*`,"g")); > auto c = m.captures; > > writeln(c); > > return 0; > } > > --------------------------------------------------------------------------- > > Content of testregexd.txt: > ---------------------------------------------------------------------------- > > <n=hello <n=goodbye > > ---------------------------------------------------------------------------- > > Any way to workaround ? > > Thanks ! > > Larry Have you tried iterating over m? This works for me: import std.stdio; import std.regex; import std.file; import std.format; int main(char[][] args) { string fl = " <n=hello <n=goodbye "; auto m = match(fl, regex(`(<n=(?:hello|goodbye))`,"g")); foreach (c; m) writeln(c); return 0; } -- Simen |
July 15, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | Humm, A copy-paste of your code lead to : "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[segmentation fault" So it doesn't work for me. I use gdc if it might help ! |
July 15, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to Larry | 15-Jul-2013 14:21, Larry пишет: > Humm, > > A copy-paste of your code lead to : > > "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[segmentation > fault" > > So it doesn't work for me. > > I use gdc if it might help ! It looks like a _very_ old GDC. What's you version string/OS/package ? -- Dmitry Olshansky |
July 16, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | I have gdc 4.6 on Debian testing. Is that so old ? |
July 16, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to Larry | On Tue, Jul 16, 2013 at 08:15:16AM +0200, Larry wrote: > I have gdc 4.6 on Debian testing. > > Is that so old ? That is extremely old. You want to get gdc-4.8.1 from unstable, if you can. A great number of bugs have been fixed since gdc-4.6; in fact, the entire std.regex has been replaced, which is probably why you're seeing these problems with regexes that the rest of us don't see. T -- If it's green, it's biology, If it stinks, it's chemistry, If it has numbers it's math, If it doesn't work, it's technology. |
July 16, 2013 Re: Types of regex | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | AAAh !! Got it ! I will make the switch ! Thanks a lot :) Larry |
Copyright © 1999-2021 by the D Language Foundation