www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - RegExp "." dos not match any character, as it misses newline

reply yidabu <yidabu.nospam gmail.com> writes:
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 03 2007
parent torhu <fake address.dude> writes:
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/
May 04 2007