# Help with regular expression

**URL:** <https://www.ruby-forum.com/t/help-with-regular-expression/171613>\
**Category:** Rails\
**Created:** [July 6, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/help-with-regular-expression/171613 "2009-07-06T17:36:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [July 6, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/help-with-regular-expression/171613/1 "2009-07-06T17:36:05Z")

</div>

First at all sory if my english is not the best.  
We have a problem in our web when a user writes a long url. The  
structure of the web becomes ugly…  
First, we tried to solve this poblem with CSS. We implemented something  
like that:

msgforo .p {  
overflow: hidden;  
word-wrap: break-word;  
}

but it wasn’t the solution for our problem because some words at the end  
of the line repeat it in the next one. Something like that:

* * *

## someone can help me with my doubt?

## becomes to:

## someone can help me with with my doubt?

We are thinking to solve this problem using regular expressions,we want  
to detect the urls and turn these into a links.  
With this regular expression:  
(\b(https?|ftp|file)\S+|\b(www?|ftp|file)\S+) I can detect the urls (Is  
checked in [www.rubular.com](http://www.rubular.com) great page to test our expressions).  
But i have a big problem, I only want to turn into a link the urls what  
there isn’t into \<a href=“www…” and \<img source=“www”. These kind of  
urls must stay with no changes.

Somebody can help me? I don’t know how create a distinction between the  
two kinds of urls.

Thank a lot
