String & delimit
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed Apr 4 01:03:19 PDT 2007
Gregor Kopp wrote:
> ---begin
> import std.stdio;
> import std.regexp;
> void main()
> {
> auto s = "blablabla thisis a string example <i_need_this_text> ole!";
> auto m = std.regexp.search(s, "<([^>]+)>");
> if (m) writefln("%s", m.match(0));
> }
> ---end
>
> which prints <i_need_this_text>
>
> I don't have time to take a closer look at your pattern so that it
> prints only i_need_this_text. I always get headache on Regexp ;)
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...
More information about the Digitalmars-d
mailing list