Regexp madness

OK you Regexp gurus out there (has anyone noticed the relative size of
regexp threads -anything with regexp seems to excite lots of attention).

I have a puzzler. I’ve been combing the ruby-talk archives trying to
convert the BlogRD format to Textile.
BlogRD marks links with ((< >)) and I thought it would be simple to use
the pattern /((<(.+)>)) to get the links.

Problem:

Having two links in the same block of text completely screws up the
results:

TXT=“((< Link one >)) and a bit further down ((< Link two >))”
LINK=/((<(.+)>))/

TXT=~LINK
p $1

" Link one >)) and a bit further down ((< Link two "

I was expecting " Link one "
Why the result? Where id I go wrong?
V.-
P.S.
Take your time,I solved the parsing problem another way.

http://www.braveworld.net/riva

I just answered this is the other regexp thread. If you put a ?
you’re regexp becomes non-greedy

LINK=/((<(.+?)>))/

On Apr 1, 2006, at 9:31 AM, Damphyr wrote:

Why the result? Where id I go wrong?

I see you already got an answer to the other question, I will tackle
this one. In a Regexp, .+ means one or more of anything, but (and
here is the kicker) as many as possible. It will keep eating
characters as long as it can, with the expression still being true.

See Chris reply for how to turn it into one or more of anything, but
as few as possible.

James Edward G. II

Chris A. wrote:

I just answered this is the other regexp thread. If you put a ?
you’re regexp becomes non-greedy

LINK=/((<(.+?)>))/

Yeap, it had to be something like this. Nice, thanks. Now I know.
Oh well, I’ll just change the code once more, regexps make it so much
more compact :slight_smile:
V.-


http://www.braveworld.net/riva