javascript와 regex를 사용하여 텍스트를 바꿔야합니다. 이러한 단어가 borex, edge 및 rss 피드로 대체되면 borex, edge 및 rss 피드으로 바뀝니다. 텍스트가 다음과 같이 표시됩니다. 내가 시도regex에서 텍스트 바꾸기
<body>
<img src="http://some.web.site/image.jpg" title="borex" />
These words are highlighted: <b>borex</b>, <b>edge</b>, <b>rss feeds</b> while these words are not: bewedge, borexlumina, rss feedssss
</body>
:
<body>
<img src="http://some.web.site/image.jpg" title="borex" />
These words are highlighted: borex, edge, rss feeds while these words are not: bewedge, borexlumina, rss feedssss
</body>
로 대체하기
var str = document.getElementByTagName("body")
str.replace(/borex/g,'<b>borex</b>').replace(/edge/g,'<b>edge</b>').replace(/rss feeds/,'<b>rss feeds</b>')
이 그들 모두를 가져옵니다. 다른 단어의 일부가 아닌 단어는 어떻게 만듭니 까? 다른 제안
가
당신의 'str' 변수는 실제로 텍스트 문자열을 포함하지 않습니다 ... –