javascript - 正则表达式path.match(/user/);

标签 javascript regex

   var path = '/user/tobi'

   path.match(/user/);
      //result: ["user"]
   path.match(/(user)/);
    //result: ["user", "user”]

为什么添加“()”会导致两个用户的结果?

最佳答案

看看regexps documentation .

String#match返回由匹配字符串和所有 submatches 组成的数组,由括号中的正则表达式声明。

关于javascript - 正则表达式path.match(/user/);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20137335/

相关文章:

javascript - 将 blob URL 转换为普通 URL

javascript - Jade JS 不输出对象属性,但输出 _id 和 __v 好吗?

jquery - 货币正则表达式

java - java中使用正则表达式进行字符串验证

jQuery 匹配正则表达式

javascript - 如何直接从服务器端过滤的存储中获取值

javascript - 通过云码删除解析文件

javascript - HTML5 Canvas : curve image along the path

Java 正则表达式匹配拉丁字母对应字符的变音符号

php - preg_match 只有 4 位数字