May 03, 2007 RegExp "." dos not match any character, as it misses newline | ||||
|---|---|---|---|---|
| ||||
code:
import std.stdio;
import std.regexp;
void main()
{
char[] str = r"a
b";
char[] pattern = ".+";
if ( RegExp(pattern).test(str) )
{
str = RegExp(pattern).match(str)[0];//无论用什么Attribute,总是只匹配第一行的a,也就是.无法跨行
writefln(str);
}
else {writefln("failed");}
}
output:a
seems "." dos not match any character, as it misses newline
| ||||
May 04, 2007 Re: RegExp "." dos not match any character, as it misses newline | ||||
|---|---|---|---|---|
| ||||
Posted in reply to yidabu | yidabu wrote: > code: > import std.stdio; > import std.regexp; > > void main() > { > char[] str = r"a > b"; > char[] pattern = ".+"; > if ( RegExp(pattern).test(str) ) > { > str = RegExp(pattern).match(str)[0];//无论用什么Attribute,总是只匹配第一行的a,也就是.无法跨行 > writefln(str); > } > else {writefln("failed");} > } > > output:a > > seems "." dos not match any character, as it misses newline That's the way regexes work. I wish the docs for "." would say "Matches any character, except a newline". Because people have asked this before. Good regex tester here, much easier to try out stuff: http://www.stringtools.com/ | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply