SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Document</title>
	<style>
		.yellow {
			background: yellow;
			border-radius:
		}
	</style>
</head>

<body></body>
<script>
	function format(text, formatText) {
      const a = formatText.sort((a, b) => b.length - a.length);
      const res=text.replace(
        new RegExp('(' + a.join('|') + ')', 'g'),
        '<span class="yellow">$1</span>'
      );
      return res
    }

    const formatText = ['明天联系', '记得联系'];
    const text ="那我们明天联系,记得联系"

    document.write(format(text, formatText));

</script>

</html>