www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Types of regex

reply "Larry" <deco33 hotmail.fr> writes:
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
Jul 15 2013
parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
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
Jul 15 2013
parent reply "Larry" <deco33 hotmail.fr> writes:
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 !
Jul 15 2013
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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
Jul 15 2013
parent reply "Larry" <deco33 hotmail.fr> writes:
I have gdc 4.6 on Debian testing.

Is that so old ?
Jul 15 2013
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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.
Jul 16 2013
parent "Larry" <deco33 hotmail.fr> writes:
AAAh !!

Got it !

I will make the switch !

Thanks a lot :)

Larry
Jul 16 2013