# Regexp madness

**URL:** <https://www.ruby-forum.com/t/regexp-madness/93396>\
**Category:** Ruby\
**Created:** [April 1, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/regexp-madness/93396 "2006-04-01T17:33:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/regexp-madness/93396/1 "2006-04-01T17:33:00Z")

</div>

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.braveworld.net/riva)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2006, 6:15pm UTC](https://www.ruby-forum.com/t/regexp-madness/93396/2 "2006-04-01T18:15:44Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/regexp-madness/93396/3 "2006-04-01T18:55:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/regexp-madness/93396/4 "2006-04-01T20:24:14Z")

</div>

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 🙂  
V.-

–  
[http://www.braveworld.net/riva](http://www.braveworld.net/riva)
