我想匹配具有以下形式的 URL 的某些部分:
http://example.com/somepath/this-is-composed-of-hypens-3144/someotherpath
更准确地说,我只想匹配由所有连字符组成并以数字结尾的部分。所以,我想提取this-is-composed-of-hypens-3144上述 URL 中的部分。我有这样的事情:
const re = /[a-z]*-[a-z]*-[0-9]*/gis;
const match = re.exec(url);
return (match && match.length) ? match[0] : null;
但是,这仅在有 2 个连字符时才有效,但是,在我的情况下,连字符的数量可以是任意的。如何使我的正则表达式适用于任意数量的连字符?
人到中年有点甜
相关分类