what I want is use sample.sub(\['<>%$#!|]\,"")
...
But I only can replace the first occurence of the chars specified in the
reg exp
How can I replace all occurences?
Use gsub instead of sub.
···
--
NP: Falkenbach - Homeward shore
Ist so, weil ist so
Bleibt so, weil war so
If you want, you could tell gsub to replace everything that is not a-z
or A-Z or a white space character
sample = "thi's is a tes<>%$#!|t"
sample.gsub(/[^a-zA-Z\s]/,"")
"this is a test"
···
On 3/18/07, Harry <ruby.hardware@gmail.com> wrote:
On 3/18/07, J. mp <joaomiguel.pereira@gmail.com> wrote:
>
> sample = "thi's is a tes<>%$#!|t"
>
> what I want is use sample.sub(\['<>%$#!|]\,"")
> and the outcome shoudl be
>
> "this is a test"
>
> But I only can replace the first occurence of the chars specified in the
> reg exp
>
> How can I replace all occurences?
>
But, wouldn't it be easier to do something like this?
sample = "thi's is a tes<>%$###!!!!!###!|t"
y = sample.delete("#!%<'>$|")
puts y