# How to match any character with ruby regexp?

**URL:** <https://www.ruby-forum.com/t/how-to-match-any-character-with-ruby-regexp/135990>\
**Category:** Ruby\
**Created:** [April 27, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/how-to-match-any-character-with-ruby-regexp/135990 "2008-04-27T18:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 27, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/how-to-match-any-character-with-ruby-regexp/135990/1 "2008-04-27T18:44:42Z")

</div>

I am writing a method to strip out (the link tag) from input text,  
and I use the gsub method to do the job:

 

> > str = “please vist \<a href=”“[http://www.abc.com](http://www.abc.com)”" title=““abc””\>abc.com for more info."  
> > str.gsub(Regexp.new(“\</?a(.)\*?\>”), “”)  
> > =\>“please vist [abc.com](http://abc.com) for more info.”

It seems work well, but I’m not confident that the (.)\* will safelly  
match all the characters inside a tag, for example, what if there is  
a new line?  
So, for ruby regex, which symbol can be surely used to represent any  
character of a string? Thanks.

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 27, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/how-to-match-any-character-with-ruby-regexp/135990/2 "2008-04-27T19:06:18Z")

</div>

On 27.04.2008 18:44, Nanyang Z. wrote:

> I am writing a method to strip out (the link tag) from input text,  
> and I use the gsub method to do the job:
> 
>  
> 
> > > str = “please vist \<a href=”“[http://www.abc.com](http://www.abc.com)”" title=““abc””\>abc.com for more info."  
> > > str.gsub(Regexp.new(“\</?a(.)\*?\>”), “”)  
> > > =\>“please vist [abc.com](http://abc.com) for more info.”
> 
> It seems work well, but I’m not confident that the (.)\* will safelly  
> match all the characters inside a tag, for example, what if there is  
> a new line?

 

irb(main):004:0\> “a\nb”.match(/.+/).to\_a  
=\> [“a”]  
irb(main):005:0\> “a\nb”.match(/.+/m).to\_a  
=\> [“a\nb”]

 

> So, for ruby regex, which symbol can be surely used to represent any  
> character of a string? Thanks.

 

A dot.

 

robert

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 27, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/how-to-match-any-character-with-ruby-regexp/135990/3 "2008-04-27T19:19:58Z")

</div>

> irb(main):005:0\> “a\nb”.match(/.+/m).to\_a  
> =\> [“a\nb”]

Thank you for your help.
