There is a regular session in which you need to use a variable, for example, so that it is in the form:
replace(/<[\s+]?тут должна быть переменная[\s+]?([^<]*)?>/gim, '<переменная $1 />');
How to implement this?
There is a regular session in which you need to use a variable, for example, so that it is in the form:
replace(/<[\s+]?тут должна быть переменная[\s+]?([^<]*)?>/gim, '<переменная $1 />');
How to implement this?
var re = new RegExp('<[\s+]?' + variable + '[\s+]?([^<]*)?>', 'gim');
Look here. Variables can be organized through brackets and call $ 1- $ 9.
Finds x and remembers. This is called “memory brackets”. For example, / (foo) / will find and remember 'foo' in "foo bar." The found substring is stored in the search result array or in the predefined properties of the RegExp object: $ 1, ..., $ 9. In addition, brackets combine what is in them into a single element of the pattern. For example, (abc) * - repeating abc 0 or more times.
In general, here is a useful article about regulars .
Source: https://ru.stackoverflow.com/questions/82765/
All Articles