Answer the question
In order to leave comments, you need to log in
How to replace character with link in regexp?
There is a line 'Counting words: 隻|只 zhī 猫|母 māo'
where 隻,猫 = old version of the character
and 只,母 - modern
version Should remove the traditional versions of "隻|" "猫|"
The result will be the string 'Counting words: 只 zhī 母 māo'
And from the remaining hieroglyphs to make links, it will turn out
'Счётные слова: <a href='http://localhost:4000/search?q=只'>只</a> zhī <a href='http://localhost:4000/search?q=母'>母</a> māo'
Answer the question
In order to leave comments, you need to log in
If you wrap in brackets (i.e. remember in this case) the second character, then in the second argument of the replace function it can be displayed through $ 1 (the count here starts from one)
phrase.replace(/.\|(.)/g, '<a href="http://localhost:4000/search?q=$1">$1</a>')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question