Javascript 正则表达式在FireFox中不工作,如何使这个正则表达式在FireFox中工作?

Javascript 正则表达式在FireFox中不工作,如何使这个正则表达式在FireFox中工作?,javascript,Javascript,我有以下regex string.match(/(?<notification_ID>\d+)/g) 但是,现在它返回null 我想要的是基于字符串返回通知ID 例如,应返回14 如何使正则表达式在所有浏览器中都能工作 如果您使用的是Chrome,那么这个代码段就可以了 var字符串class='1〕https://example.com/here-comes-a-path/#!/通知-14'; console.log(string.match(/(?\d+)/g))像这样的正

我有以下
regex

string.match(/(?<notification_ID>\d+)/g)
但是,现在它返回
null

我想要的是基于字符串返回通知ID

例如,应返回
14

如何使正则表达式在所有浏览器中都能工作


如果您使用的是Chrome,那么这个代码段就可以了

var字符串class='1〕https://example.com/here-comes-a-path/#!/通知-14';

console.log(string.match(/(?\d+)/g))
像这样的正则表达式可以工作:

notification-(\d+)
它匹配
通知-
,然后捕获
(\d+)
中的一个或多个数字

const regex=/notification-(\d+)/
常量字符串=”https://example.com/here-comes-a-path/#!/notification-14“
const matches=string.match(regex);

console.log(匹配[1])像这样的正则表达式可以工作:

notification-(\d+)
它匹配
通知-
,然后捕获
(\d+)
中的一个或多个数字

const regex=/notification-(\d+)/
常量字符串=”https://example.com/here-comes-a-path/#!/notification-14“
const matches=string.match(regex);
console.log(匹配[1])
var字符串class='1〕https://example.com/here-comes-a-path/#!/通知-14';
console.log(string.match(/notification-(\d+)/g))
var字符串class='1〕https://example.com/here-comes-a-path/#!/通知-14';

console.log(string.match(/notification-(\d+)/g))
为什么不使用
str.match(/notification-(\d+)/)[1]
。您的正则表达式只匹配字符串中任意位置的数字。尝试使用string
htt111p://example.com/1111/…
。当Chrome支持时,您使用的FireFox版本可能不受支持。为什么不使用
str.match(/notification-(\d+)/)[1]
。您的正则表达式只匹配字符串中任意位置的数字。尝试使用string
htt111p://example.com/1111/…
。当Chrome支持时,您使用的FireFox版本可能不受支持。