这次给大家带来用正则表达式让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
给大家看一下完整的代码
相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
相关阅读:
怎么实现springmvc接收jquery提交的数组后提取数据
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!