忽略数字索引获取子字符串

4

I have the following two strings:

var block = "//div[@class='gd-row browse-grid-row'][1]/div[@class='gd-col gu3'][1]/div"

var full =  "//div[@class='gd-row browse-grid-row'][1]/div[@class='gd-col gu3'][2]/div[@class='product-unit unit-4 browse-product new-design ']/div[@class='pu-details lastUnit']/div[@class='pu-price']/div[@class='pu-border-top']/div[@class='pu-final']/span"

我需要检查一个字符串是否为另一个字符串的子串,忽略所有索引。

基本上,我想忽略以下格式的内容:

'[数字]'

在检查子串时如何在JavaScript中实现?


3
你可以使用正则表达式去除[数字],然后从那里开始检查。你到目前为止尝试了什么? - winhowes
str.replace(/\[\d*\]/g, '') - Avinash Raj
我不太熟悉正则表达式。我一直试图加入条件来进行检查!没想到可以使用替换。谢谢。 - pd176
1个回答

5

使用 replaceindexOf

var regex = regex = /\[\d+\]/g;

full.replace(regex, '').indexOf(block.replace(regex, '')) > -1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接