Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Regex

Moderators: kris

Posted: 03/04/08 08:17:58

Hi,

I have installed tango 0.99.5 and it broke my Regex-es. How compatible is the new Regex with the old (Phobos) one? I read the docs but they are almost missing. For example my old regex is r"\[url([ \t]*=[ \t]*([\]\t\r\n]+)[ \t]*)?\](.*)\/url\" . It is supposed to turn something like [url=http://google.com]link[/url] to HTML code, but now it produces invalid utf8 sequence and breaks my program...

Thanks, bobef

Author Message

Posted: 03/04/08 09:04:23

Could you file a ticket specifying how to reproduce this problem? The regex and example input from your post seem to work.

Posted: 03/04/08 11:10:48

I couldn't reproduce it out of my program. I.e. I can't make it output invalid utf8 sequence, but it is not working anyway. It outputs empty string. The same expression works with Phobos' Regex.sub. Maybe I am doing something wrong? Here is an example:

import tango.io.Console;
import tango.text.Regex;

void main()
{
	char[] str="<html>
  <head>
    <meta name=\"generator\" content=\"h-smile:richtext\"/>
    <meta name=\"source\"/>
    <meta name=\"source\"/>
  </head>
<body>
  asdasd<p><strong>проба</strong> 2</p>
  <p> </p>
  <p> </p>
  <p>[url=folder2/test.txt]dokument[/url][url=html40.pdf]HTML 4.0 help[/url]</p>
</body>
</html>";
	str=Regex(r"\[url([ \t]*=[ \t]*([^\]\t\r\n]+)[ \t]*)?\](.*)\[/url\]").replaceAll(str,delegate(Regex r)
	{
		Cout("never gets here").newline.flush;
		//never gets here not with r"\[/url\]" nor r"\[url(=([^\]]+))?\](.*)\[/url\]"
		auto m1=r.match(2);
		if(m1.length==0) return cast(char[])"";
		auto m2=r.match(3);
		if(m2.length==0) m2=m1;
		return "<a href=\""~"linkto://"~m1~"\">"~m2~"</a>";
	});
	Cout(str).newline.flush;
}