www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.regexp and std.file listdir

reply "jicman" <jic spam.me> writes:
I have this program:

import std.stdio;
import std.file;
import std.regexp;

int main(char[][] args)
{
  char[][] f = listdir(r"d:\tmp",RegExp(r"*.pdf","i"));
  writefln(f.length);
  return(0);
}

When I run it, I get,

Error: *+? not allowed in atom

Why?

thanks,

josé
Aug 23 2006
parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
That's not a regular expression.  I think what you want is:

listdir(r"d:\tmp", RegExp(r"\.pdf$", "i"));

In a regular expression, "*" means "zero or more of the previous 
character.  So, "a*" would match "", "a", "aa", "aaaa", etc.

A dot means "any character except \n", so that wouldn't work like you 
expected either.  You have to escape it.

A $ means "end of line", so that means that the .pdf has to be at the 
end of the string, not just anywhere.

For more information, see:
http://www.digitalmars.com/ctg/regular.html

-[Unknown]


 I have this program:
 
 import std.stdio;
 import std.file;
 import std.regexp;
 
 int main(char[][] args)
 {
   char[][] f = listdir(r"d:\tmp",RegExp(r"*.pdf","i"));
   writefln(f.length);
   return(0);
 }
 
 When I run it, I get,
 
 Error: *+? not allowed in atom
 
 Why?
 
 thanks,
 
 josé
 
 
Aug 23 2006