【发布时间】:2018-01-18 08:31:17
【问题描述】:
我的代码运行良好并返回我的字符串:“91308543 91502466 91502466 91503362 91503362 91308543 9851236”。
function f () {
var text = ("91308543 91502466 91502466 91503362 91503362 91308543 9851236");
var regex = /(9\d{7})/gm;
var compare = text.match(regex);
var result = compare.join(", ");
return result; }
f ();
我的问题是我想摆脱重复的数字。 我已尝试在 JS 控制台中改用此正则表达式:“/(9\d{7})(?!.*\1)/gm;”它可以工作,但不幸的是,我使用的引擎(Esko Automation Engine)根本不工作。我收到此错误:
javax.script.ScriptException:TypeError:null has no such function"join" in at line number 9.
有人知道不返回字符串中重复数字的解决方案或其他方法吗?
【问题讨论】:
-
@Cerbrus OP 希望通过正则表达式提取唯一数字。有一种方法可以使用正则表达式来做到这一点。那么,这可以重新打开吗?
-
@Tushar:如果 OP 想用手提钻切结婚蛋糕,你不建议他们改用刀吗?
-
呵呵。我现在明白了:)
-
也许 OP 是个 YouTube 名人,想在 liveleak 出名
标签: javascript arrays regex duplicates