Regexp madness

D

Damphyr

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

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.
 
J

James Edward Gray II

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 Gray II
 
D

Damphyr

Chris said:
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 :)
V.-

--
http://www.braveworld.net/riva

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top