Home > Web Front-end > JS Tutorial > body text

How to use regular expressions to highlight JavaScript code

php中世界最好的语言
Release: 2018-01-08 10:45:20
Original
2001 people have browsed it

这次给大家带来用正则表达式JavaScript的代码高亮,怎样用正则表达式让JavaScript的代码高亮?用正则表达式让JavaScript的代码高亮的注意事项有哪些,下面就是实战案例,一起来看一下。

今天想改一下JS的高亮的配色,憋了一下午憋出了这个这个正则表达式。
  下面这老长老长了的玩意儿是个正则表达式,看到了别吓坏了。

/(\/\/.*|\/\*[\S\s]+?\*\/)|((["'])(?:\\.|[^\\\n])*?\3)|\b(break|continue|do|for|in|function|if|else|return|switch|this|throw|try|catch|finally|var|while|with|case|new|typeof|instance|delete|void)\b|\b(Object|Array|String|Number|Boolean|Function|RegExp|Date|Math|window|document|navigator|location)\b|\b(true|false)\b|\b(null|undefined|NaN)\b|(?:[^\W\d]|\$)[\$\w]*|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?(?:[eE]\d+)?)|(?:[^\)\]\}]|^)(\/(?!\*)(?:\\.|[^\\\/\n])+?\/[gim]*)|[\S\s]/g
Copy after login

给大家看一下完整的代码

Copy after login


相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

jQuery如何实现前端搜索功能

怎么实现springmvc接收jquery提交的数组后提取数据

vue.js的语法及常用指令的详解

The above is the detailed content of How to use regular expressions to highlight JavaScript code. 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
Popular Tutorials
More>
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!