<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">	
	<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
	<link rel="stylesheet" href="js_style.css" />
	<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
	<script src="lesson34.js"></script>
</head>
<body>
	<div id="less34">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
					<h2>Поиск слова используя регулярное выражение</h2>
					<textarea id="text_34" cols="35" rows="5">Ехал Грека через реку, видит Грека в реке рак, сунул Грека руку в реку, рак за руку Греку цап.</textarea><br>
					<input type="text" id="word_34" placeholder="Введите слово"><br><br>
					<input type="button" id="btn_34" value="Найти слово" onclick="FindWord()"><br><br>
					<h4 id="output_34"></h4>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
#less34{
  margin-top: 40px;
  margin-bottom: 40px;
}
#less34 h2{
  margin-bottom: 25px;
}
span{
  color:red;
}
function FindWord() {
    var gText = document.getElementById('text_34').value;
    var gWord = document.getElementById('word_34').value;
    var gOutput = document.getElementById('output_34');


    var reg = new RegExp(gWord , 'gi');
    var newWord = gText.match(reg);
    
    
    var replaceText = gText.replaceAll(newWord, `<span>${newWord}</span>`);
    gOutput.innerHTML = replaceText;

}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.