April 04, 2007
Frits van Bommel schrieb:
> It's quite easy, in fact it's a one-character patch:
>     if (m) writefln("%s", m.match(1));
> 
> A parameter > 0 passed to match(int) returns the part that matches the corresponding pair of parentheses, and the correct subexpression was already parenthesized...


Thank you for this info! Maybe this all helps Dié with his problem. Lets hope so ;)
April 04, 2007
Dié schrieb:
> Hello
> 
> I have this string:
> 
> blablabla thisis a string example <i_need_this_text>
> 

Hello Dié,
did you get it worked out?

If not:

import std.regexp;
int main(char[][] args)
{
	char[] message = "just <a> few <tags>, no <nesting here>";
	RegExp rg = new RegExp("<.*>", "g");
	char[][] res = rg.match(message);

	assert(res[0] == "<a>");
	assert(res[1] == "<tags>");
	assert(res[2] == "<nesting here>");

	// remove the delimiters
	foreach(inout v; res)
		v = v[1..$-1];

	assert(res[0] == "a");
	assert(res[1] == "tags");
	assert(res[2] == "nesting here");
}

If you need nesting (is this possible with RexExp? Found nothing...)
you can use the function
	char[][] findNesting(char[] string, char left, char right)
in the file (strex.d) I attached,
which splits
	"this <test> is <advanced, as <you can> see>a<b<c>d>><e"
in
	"test"
	"advanced, as <you can> see"
	"you can"
	"b<c>d"
	"c"
(see test.d for examples)

If you want correct nesting but only the innermost tags,
apply the function
	bool containsTag(char[] string, char left, char right)
also in the attached strex.d in combination with
	char[][] findNesting(char[] string, char left, char right)

david


1 2
Next ›   Last »