www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Regular expressions

reply Markus Dangl <danglm in.tum.de> writes:
Hi again,

this time i got a problem with regexp. The documentation says:

int search(char[] string)
     Search string[] for match with regular expression.
     Returns 	Description
     >=0 	index of match
     -1 	no match

But this program:

<code>
private import std.regexp;
private import std.stdio;

int main(char[][] arg)
{
   char[] str1 = "TEST";
   char[] str2 = "TEST.bmp";
   RegExp regexp = new RegExp("\\.bmp$", "i");

   int i = regexp.search(str1);
   int j = regexp.search(str2);

   writef("regexp.search(\"%s\") == %s\n", str1, i);
   writef("regexp.search(\"%s\") == %s\n", str2, j);

   return 0;
}
</code>

prints:

regexp.search("TEST") == 0
regexp.search("TEST.bmp") == 1

... what am i doing wrong?

Thanks,
Markus
Jan 02 2005
parent reply h3r3tic <foo bar.baz> writes:
Markus Dangl wrote:
 (...)
 
 prints:
 
 regexp.search("TEST") == 0
 regexp.search("TEST.bmp") == 1
 
 ... what am i doing wrong?

I don't know. That's weird, here's my output: regexp.search("TEST") == -1 regexp.search("TEST.bmp") == 4 DMD.110; WinXP.SP2.En
Jan 02 2005
parent reply Markus Dangl <danglm in.tum.de> writes:
h3r3tic schrieb:
 Markus Dangl wrote:
 
 (...)

 prints:

 regexp.search("TEST") == 0
 regexp.search("TEST.bmp") == 1

 ... what am i doing wrong?

I don't know. That's weird, here's my output: regexp.search("TEST") == -1 regexp.search("TEST.bmp") == 4 DMD.110; WinXP.SP2.En

oh i forgot: DMD.110; WinXP.SP2.De This "bug" occurs since i upgraded from DMD.109
Jan 02 2005
parent "Walter" <newshound digitalmars.com> writes:
"Markus Dangl" <danglm in.tum.de> wrote in message
news:craef3$um0$1 digitaldaemon.com...
 h3r3tic schrieb:
 Markus Dangl wrote:

 (...)

 prints:

 regexp.search("TEST") == 0
 regexp.search("TEST.bmp") == 1

 ... what am i doing wrong?

I don't know. That's weird, here's my output: regexp.search("TEST") == -1 regexp.search("TEST.bmp") == 4 DMD.110; WinXP.SP2.En

oh i forgot: DMD.110; WinXP.SP2.De This "bug" occurs since i upgraded from DMD.109

I also get the correct results (-1 and 4) with 110.
Jan 03 2005