本文介绍了JavaScript正则表达式问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
有这样一个正则表达式 /.(w+)/g,exec一个字符串'a.b.c',结果是什么?不是得到.b和.c吗?
/\.(\w+)/g.exec('a.b.c')解决方案var reg = /\.(\w+)/g undefined var str = 'a.b.c'; undefined reg.exec(str) [".b", "b"] reg.exec(str) [".c", "c"] reg.exec(str) nullReturn value
If the match succeeds, the exec() method returns an array and updates properties of the regular expression object. The returned array has the matched text as the first item, and then one item for each capturing parenthesis that matched containing the text that was captured.
If the match fails, the exec() method returns null.
developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
更多推荐
JavaScript正则表达式问题?
发布评论