比较2个字符串时忽略这些字符串中间的数字

时间:2014-01-29 12:05:08

标签: javascript jquery

我在比较Jquery中的两个变量值,但在这里我需要忽略它们之间的数字。 代码如下:

var value1=Earn a score greater than or equal to 3 points for assignment certifictaion Issue Testing ;

var value2=Earn a score greater than or equal to 6 points for assignment certifictaion Issue Testing ;

当使用j查询比较两个字符串时,无论两个字符串中间是否存在数字,我都希望进行比较

1 个答案:

答案 0 :(得分:3)

为什么不用空格替换所有数字?然后比较两个字符串?

var value1 = "Earn a score greater than or equal to 3 points for assignment certifictaion Issue Testing";
var value2= "Earn a score greater than or equal to 61 points for assignment certifictaion Issue Testing";

var result = value1.replace(/\d/g, "") === value2.replace(/\d/g, "");
alert(result)