# What's wrong with my method and regular expression?

**URL:** <https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899>\
**Category:** Ruby\
**Created:** [December 18, 2008, 1:10am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899 "2008-12-18T01:10:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![equinox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@equinox](https://www.ruby-forum.com/u/equinox)\
**Post date:** [December 18, 2008, 1:10am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899/1 "2008-12-18T01:10:42Z")

</div>

The code is

[http://pastie.org/341880](http://pastie.org/341880)

And i want it to return

nil  
www.yahoo.co.in  
/~testing/i.html

but when I run this code, why doesn’t the www.yahoo.co.in detected?

---

<div class="post-metadata">

**Author:** ![equinox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@equinox](https://www.ruby-forum.com/u/equinox)\
**Post date:** [December 18, 2008, 2:05am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899/2 "2008-12-18T02:05:41Z")

</div>

On Dec 17, 7:07 pm, equinox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The code is
> 
> [http://pastie.org/341880](http://pastie.org/341880)
> 
> And i want it to return
> 
> nilwww.yahoo.co.in  
> /~testing/i.html
> 
> but when I run this code, why doesn’t thewww.yahoo.co.indetected?

You might want to play with your regex on Rubular (http://  
[rubular.com/](http://rubular.com/))  
A little experimentation shows that you probably want to include  
‘http://’  
in your input string

cheers

---

<div class="post-metadata">

**Author:** ![equinox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@equinox](https://www.ruby-forum.com/u/equinox)\
**Post date:** [December 18, 2008, 2:10am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899/3 "2008-12-18T02:10:22Z")

</div>

On Dec 17, 6:04 pm, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > but when I run this code, why doesn’t thewww.yahoo.co.indetected?
> 
> You might want to play with your regex on Rubular (http://  
> [rubular.com/](http://rubular.com/))  
> A little experimentation shows that you probably want to include  
> ‘http://’  
> in your input string
> 
> cheers

the code should work for both, if there’s no http:// then it should  
print out:

nil  
www.yahoo.co.in  
/~testing/i.html

if there is then it should print:

http  
www.yahoo.co.in  
/~testing/i.html

---

<div class="post-metadata">

**Author:** ![equinox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@equinox](https://www.ruby-forum.com/u/equinox)\
**Post date:** [December 18, 2008, 2:23am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-method-and-regular-expression/155899/4 "2008-12-18T02:23:14Z")

</div>

On Dec 17, 6:08 pm, equinox [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > And i want it to return  
> > > in your input string
> 
> httpwww.yahoo.co.in  
> /~testing/i.html

anyway thanks for the rubular link I was able to fix the code using  
it…
