Ric*_*ard 2 javascript regex match
我认为这个正则表达式是关于将单词转换成数组,但结果我得到null
当我想从数组[0]的"facebox otherword"中获取第二个单词时
这是正则表达式:
this.rel.match(/facebox\[?\.(\w+)\]?/)
Run Code Online (Sandbox Code Playgroud)
谢谢理查德
我相信你正在寻找的是 split() 函数:
你提到的关于将单词转换成数组的提法通常被称为拆分,所以如果你想otherword从" facebox otherword" 得到" ",你会做以下事情:
var test = "facebox otherword"
var word = test.split(' ')[1];
Run Code Online (Sandbox Code Playgroud)