On Monday 17 January 2005 04:51 pm, Assaph Mehr wrote:
| > Thanks. I _see_ now why mine wasn't working, though I don't
| > _understand_ why it wasn't working. I was using the / /x extension,
| > because I generally like to space the parts my regexps out to
| > read easier, but for some reason that causes the above to
| > match [b] instead. Oh well, I just won't do that.
|
| It has todo with the pattern matching being greedy, not the /x flag.
| your pattern will match a '[' then as many characters as possible -
| including ']' - until a final closing ']'.
| There are two solutions:
| 1. As shown, match any non ']'.
| 2. Make the match non greedy: %r{ \[(.+?)\] }x
|
| HTH,
| Assaph
| ps. If you want all occurences in the string, use string#scan instead
| of String#match.

Thanks Assaph,

I had an escape character match in the regexp:

  / [^`] \[(.+?)\] /x

That was messing it up (Don't really know why) but I just "zeroed" it:

  / (?=[^`]) \[(.+?)\] /x

And that did the trick. 

Just one of those things were you just over look what you think you know to 
the point of seizure ;)

T.