Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
how to match any character with ruby regexp?
Nanyang Zhan
4/27/2008 4:45:00 PM
I am writing a method to strip out <a> (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&q...
title=""abc"">abc.com</a> for more info."
>>str.gsub(Regexp.new("<\/?a(.)*?>"), "")
>>=>"please vist abc.com for more info."
It seems work well, but I'm not confident that the (.)* will safelly
match all the characters inside a <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.
--
Posted via
http://www.ruby-...
.
2 Answers
Robert Klemme
4/27/2008 5:02:00 PM
0
On 27.04.2008 18:44, Nanyang Zhan wrote:
> I am writing a method to strip out <a> (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&q...
title=""abc"">abc.com</a> for more info."
>>> str.gsub(Regexp.new("<\/?a(.)*?>"), "")
>>> =>"please vist abc.com for more info."
>
> It seems work well, but I'm not confident that the (.)* will safelly
> match all the characters inside a <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
Nanyang Zhan
4/27/2008 5:20:00 PM
0
> irb(main):005:0> "a\nb".match(/.+/m).to_a
> => ["a\nb"]
>
Thank you for your help.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
how to match any character with ruby regexp?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password