Answer the question
In order to leave comments, you need to log in
How to replace a digit in a string using a regular expression?
This question may seem very, very strange, but it is necessary to do exactly according to these actions. I took it as an example JavaScript
, but you can do it on any other. The main thing is to follow the rules
. There is a variable. It is a = 0;
necessary to make it a line with words. Approximately so: a = a.replace(0, /* регулярное выражение */ );
Here actually and a problem. What regular expression should be used to replace it with the words "Hello world"
In fact, you can simply do this: a = "Hello world";
But the key point is that you need to do this without using quotes. None at all! This is where the idea of using regular expressions popped into my head.
But if there is another way, please tell me how. Most importantly, you can't use quotes .
Answer the question
In order to leave comments, you need to log in
It's all right?
>>a = 0
=> 0
>> a = a.to_s.sub('0',%{hello world})
=> "hello world"
>> a
=> "hello world"
a = 123
=> 123
> > a = a.to_s.gsub(/\d+/,%{hello world})
=> "hello world"
>> a
=> "hello world"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question