var re=/world|people|Pizar/g
var str = "Disney films are favored by people all around the world, it is known to all that many of the movies are produced by Pizar animation studio";
有一個正則表達式,還有一個字符串,我想為這個字符串中所有匹配正則表達式的單詞分別都加上一個< span >包裹起來,例如:< span >world< /span >一樣。請問怎麼才能辦到呢?
var re=/(world|people|Pizar)/g
var str = "Disney films are favored by people all around the world, it is known to all that many of the movies are produced by Pizar animation studio";
str=str.replace(re,'<span>$1</span>')
alert(str)