Date: Tue, 23 Oct 2001 19:49:40 +0200 From: Roman Neuhauser <neuhauser@mobil.cz> To: freebsd-questions@freebsd.org Subject: Re: regex(3), re_format(7) and shortest match Message-ID: <20011023194940.A8947@roman.mobil.cz> In-Reply-To: <3BD5A7F4.748285AA@verizon.net> References: <3BD5A7F4.748285AA@verizon.net>
next in thread | previous in thread | raw e-mail | index | archive | help
> Date: Tue, 23 Oct 2001 10:25:08 -0700
> From: Shill <shill@free.fr>
> To: freebsd-questions@freebsd.org
> Subject: regex(3), re_format(7) and shortest match
>
> Say I have the string:
> "yo <a --- </a> hiphop <a +++ </a> fun"
>
> I want to isolate individual "<a ... </a>" subexpressions.
>
> The naive regex I used was: (<a.*</a>)
>
> Of course, that doesn't work since it returns the longest match, in my
> case "<a --- </a> hiphop <a +++ </a>".
>
> I battled with bracket expressions and collating elements for three
> hours to no avail. Can anyone tell me how to achieve the shortest match?
>
> i.e. the first call to regexec() would return "<a --- </a>" and the
> second would return "<a +++ </a>".
Try this: (<a[^]]</a>)
HTH,
Roman
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011023194940.A8947>
