digitalmars.D - remove the ";" necessity in regex ?
- Larry (34/34) Jul 14 2013 Hello,
- David (3/3) Jul 14 2013 what if you change your regex to:
- Simen Kjaeraas (10/41) Jul 14 2013 I'm confused. You are using a regex with an explicit ; at the end, and
- Larry (5/5) Jul 15 2013 Ooops !
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 ? Thanks ! Larry
Jul 14 2013
what if you change your regex to: regex(`n=(hello|goodbye);?`) Also, would be appreciated if you could post these questions to d.learn.
Jul 14 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
Jul 14 2013
Ooops ! Of course ! I forgot this semicolon.. screwed mind. Many thanks, everything works fine. Bye !
Jul 15 2013