Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript匹配中具有不同运算符的字符串_Javascript_Regex_Match - Fatal编程技术网

JavaScript匹配中具有不同运算符的字符串

JavaScript匹配中具有不同运算符的字符串,javascript,regex,match,Javascript,Regex,Match,我有以下JS变量: var tokens = str.match(/\[|\]|< number|\)|and |(?:(?!and )[^\[\]])+/g); var-tokens=str.match(/\[\]\

我有以下JS变量:

var tokens = str.match(/\[|\]|< number|\)|and |(?:(?!and )[^\[\]])+/g);
var-tokens=str.match(/\[\]\
tokens
稍后在
switch()语句中使用

这与以下情况匹配:

  • [
  • ]
  • (末尾有空格)
但是,我想在
number
之前,不仅是
  • =
  • 使用表达式
    []=?编号

    []
    表示


    =?
    是一个可选的
    =
    符号。

    尝试替换
    @Sam Hm,很好的呼叫,但我宁愿保持它干净,并且不使用
    =
    =
    令牌将是一个数组。由于两个数组只有在内存中的引用相同时才相等,我不确定如何在
    switch
    语句中使用它们。我不确定如何解决这个问题,但从
    []
    开始,它们将匹配大于或小于。@Oriol它们将在
    for
    循环中使用
    var token=tokens[I]