JavaScript正则表达式“没有重复"错误 [英] JavaScript regular expression "Nothing to repeat" error

查看:43
本文介绍了JavaScript正则表达式“没有重复"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试获取令牌的代码以对Minic语言进行词法分析时遇到此错误!

I have this error while trying to get the tokens the code to make the lexical analysis for the Minic langauge !

document.writeln("1,2 3=()9$86,7".split(/,| |=|$|/));

document.writeln("<br>");
document.writeln("int sum ( int x , int y ) { int z = x + y ; }");
document.writeln("<br>");
document.writeln("int sum ( int x , int y ) { int z = x + y ; }".split(/,|*|-|+|=|<|>|!|&|,|/));

我在调试器的最后一行出现错误Uncaught SyntaxError:无效的正则表达式:没有重复的内容!

I get error on the debugger for the last line Uncaught SyntaxError: Invalid regular expression: Nothing to repeat !!

推荐答案

您需要转义特殊字符:

/,|\*|-|\+|=|<|>|!|&|,|/

请参见需要转义哪些特殊字符:

See what special characters need to be escaped:

这篇关于JavaScript正则表达式“没有重复"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆