9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] sam regexp coverage
@ 2004-05-09 16:28 Matthias Teege
  2004-05-09 16:51 ` Rob Pike
  2004-05-10  0:23 ` boyd, rounin
  0 siblings, 2 replies; 4+ messages in thread
From: Matthias Teege @ 2004-05-09 16:28 UTC (permalink / raw)
  To: 9fans

I have another small problem with sam and regexp. I have a text
with a lot of constructs like this one:

Hello world http://my.domain:"This is a link" more text and
http://another.domain:"This is another link" follows more text

Now I try to translate the link in html syntax with
,x/(http.*)\:\".*\" s/(http.*):\"(.*\n*.*)\"/<a href=\"\1\">\2<\/a>/

The problem is, that the regexp matches both "links" not only
the first ore the second one. I've tried to find a better one but
its hopeless. ;-)

Thanks for any hint
Matthias


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sam regexp coverage
  2004-05-09 16:28 [9fans] sam regexp coverage Matthias Teege
@ 2004-05-09 16:51 ` Rob Pike
  2004-05-10  1:00   ` boyd, rounin
  2004-05-10  0:23 ` boyd, rounin
  1 sibling, 1 reply; 4+ messages in thread
From: Rob Pike @ 2004-05-09 16:51 UTC (permalink / raw)
  To: 9fans

your problem is that .* is greedy. instead of
  .*"
(maximal sequence of anything followed by quote)
write
  [^"]*"
(maximal sequence of not-quote, followed by quote).
you don't need the backslashes for : and ".

-rob

On Sun, 9 May 2004 16:28:17 0000, Matthias Teege <matthias@mteege.de> wrote:
>
> I have another small problem with sam and regexp. I have a text
> with a lot of constructs like this one:
>
> Hello world http://my.domain:"This is a link" more text and
> http://another.domain:"This is another link" follows more text
>
> Now I try to translate the link in html syntax with
> ,x/(http.*)\:\".*\" s/(http.*):\"(.*\n*.*)\"/<a href=\"\1\">\2<\/a>/
>
> The problem is, that the regexp matches both "links" not only
> the first ore the second one. I've tried to find a better one but
> its hopeless. ;-)
>
> Thanks for any hint
> Matthias
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sam regexp coverage
  2004-05-09 16:28 [9fans] sam regexp coverage Matthias Teege
  2004-05-09 16:51 ` Rob Pike
@ 2004-05-10  0:23 ` boyd, rounin
  1 sibling, 0 replies; 4+ messages in thread
From: boyd, rounin @ 2004-05-10  0:23 UTC (permalink / raw)
  To: 9fans

x (and y) are iteration operators.  so ...

once you understand them they are extremely powerful.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sam regexp coverage
  2004-05-09 16:51 ` Rob Pike
@ 2004-05-10  1:00   ` boyd, rounin
  0 siblings, 0 replies; 4+ messages in thread
From: boyd, rounin @ 2004-05-10  1:00 UTC (permalink / raw)
  To: 9fans

> your problem is that .* is greedy.

yes, as it always has been (ie. not a sam related problem).




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-05-10  1:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-09 16:28 [9fans] sam regexp coverage Matthias Teege
2004-05-09 16:51 ` Rob Pike
2004-05-10  1:00   ` boyd, rounin
2004-05-10  0:23 ` boyd, rounin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).