需要JavaScript正则表达式,仅括号中的数字,多个

问题描述 投票:0回答:1

[我想用纯JavaScript编写一个函数,该函数将类Jquery选择器与:eq(0)声明一起使用,例如遍历像这样的表

$('tr:eq(8) > td:eq(13)').val();

为此,我试图编写一个正则表达式,但我停留在这里

var str = "I don't want +5+ and not 10 or [12] nor (120) but :eq(5) and :eq(120)";
var matches = str.match(/\:eq\(\d+(\d{1,2})\)?/g);
console.log('matches: '+matches);

仅返回matches: :eq(120),而不返回所需的matches: :eq(5),:eq(120)。我在这里可以做什么?

javascript regex match
1个回答
1
投票

您可以简化您的正则表达式:

  var matches = str.match(/\:eq\(\d+\)/g);
© www.soinside.com 2019 - 2024. All rights reserved.