【发布时间】:2020-06-22 08:13:11
【问题描述】:
我在 javascript 中有一个字符串:
const str = "bugfix/SOME-9234-add-company"; // output should be SOME-9234
const str2 = "SOME/SOME-933234-add-company"; // output should be SOME-933234
const str3 = "test/SOME-5559234-add-company"; // output should be SOME-5559234
我想提取 SOME-.. 直到第一个 - 字符。
我使用了这个正则表达式,但没有用。什么是正确的正则表达式?
const s = "bugfix/SOME-9234-add-company";
const r1 = s.match(/SOME-([1-9])/);
const r2 = s.match(/SOME-(.*)/);
const r3 = s.match(/SOME-(.*)-$/);
console.log({ r1, r2, r3 });
【问题讨论】:
标签: javascript regex string