remove the ";" necessity in regex ?

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 14 14:44:15 PDT 2013


On 2013-07-14, 19:30, Larry wrote:

> Hello,
>
> I would like to be able to make a regex from a text file :
>
> [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);`));
>      auto c = m.captures;
>
>      writeln(c);
>
>      return 0;
> }
> [/code]
>
> But the main problem is that my file doesn't end with a semi colon ";".  
> And so the regex cannot find anything in the file.
>
> If I append this ";" at the end of my file, everything works as expected.
>
> [code]
> n=hello
> [/code]
> won't work whereas
> [code]
> n=hello;
> [/code]
> will.
>
> Appending ";" with a mixin won't work either because it will create a  
> new line.
>
> Any idea ?

I'm confused. You are using a regex with an explicit ; at the end, and
you are surprised it only matches strings that end with ;?

Step one: Remove the ; from the regex. Does that work?

Step two (should step one fail): Add a $ where the ; was. Does that work?

Step three (should step two fail): Give a better explanation of what the
problem you're trying to solve is. (i.e. why is there a semicolon at the
end of your regex?)

-- 
Simen


More information about the Digitalmars-d mailing list