Highlight characters using regular expressions

php中世界最好的语言
Release: 2017-12-30 17:58:02
Original
1928 people have browsed it

这次给大家带来的是用正则表达式让字符高亮显示,把数字改换成正则表达式的中文或者指定的字符,既可以高亮。还可以设置其他的高亮颜色,这篇文章就给大家好好分析一下。

红色:style='background:red;'

蓝色:style='background:blue;'

绿色:style='background:green;'

span2314的23文本213 var htmlobj = txt.replace(/(\d+)/img, "$&"); //var htmlobj = txt.replace(/([+\-]?[0-9]+(\.[0-9]+)?)/g, "$1"); // 这个也可以 //var htmlobj = txt.replace(/(\d+)/img, "$1");//这个也可以 alert("替换spna中的数字:"+htmlobj); $("#span_id").html(htmlobj);
Copy after login

相信看了以上介绍你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

JS怎样可以做到点击跳转到登陆的个人邮箱

require.js的使用方法详细介绍

Ajax应该如何使用

The above is the detailed content of Highlight characters using regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!