Topic: Regex to ignore images

I am using a custom method for auto-excerpts. This is how it looks.

[code =ruby]def excerpt(text, length = 30, end_string = '

Re: Regex to ignore images

This basic regex should do the trick: /!.+?\.(gif|jpg|png)!/
It looks for a substring with the following text:
- exclamation mark
- some text non greedily (matching as little as possible)
- a period
- either 'gif', 'jpg', or 'png'
- exclamation mark.

Then you could use a global substitution to remove those image substrings. text.gsub() will make a copy of the text string.

[code=]def excerpt(text, length = 30, end_string = '

Vincent Woo Ruby on Rails Blog

Re: Regex to ignore images

That works a treat..Thanks!

Last edited by pimpmaster (2007-06-10 08:37:49)