正在获取忽略数字索引的子字符串

Getting substring ignoring numeric indices

本文关键字:索引 字符串 数字 获取      更新时间:2023-09-26

我有以下两个字符串:

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"

我需要检查块是否是完全忽略所有索引的子字符串。

基本上我想忽略表单的所有模式:

'[number]'

检查子字符串时。我如何在JavaScript中做到这一点?

使用replaceindexOf:

var regex = regex = /'['d+']/g;
full.replace(regex, '').indexOf(block.replace(regex, '')) > -1