Variable with a regex in JavaScript
Regular expressions can be placed into variables. Let's look at an example. Let's say we have the following string:
javascriptlet str = 'aaa bbb ccc';
Let's say we have the following code with a regex:
javascriptlet res = str.replace(/\w+/, '!');
Let's move the regular expression into a variable:
javascriptlet reg = /\w+/;
let res = str.replace(reg, '!');
Задание 1
Move the regex into a variable in the following code:
javascriptlet str = 'a aa aaa aaaa aaaa';
let res = str.replace(/a+/, '!');