Regular Express for Javascript - 获取任何字符后在开头包含特定单词,直到某个字符出现

Regular Express for Javascript - Contain a specific word in the beginning after get any character until a certain character comes

我需要某种类型的正则表达式,我需要从一个字符串中列出特殊类型的字符串。输入示例:

str = 'this is extra data which i do not need /type/123456/weqweqweqweqw/ these are more extra data which i dont need /'

需要的结果:

/type/123456/weqweqweqweqw/

此处的 /type/ 字符串将是常量,其余字符串将是动态的,即 123456/weqweqweqweqw,最后一个字符串将是 /.

我试过了:

var myRe = /\/type\/(.*)\//g

但这匹配从 /type/ 到字符串末尾的所有内容。

不是重复 .,它将匹配任何内容,而是通过 \S+ 重复除 space 之外的任何内容,这样只有字符串的 URL 部分会被匹配匹配:

const str = 'this is extra data which i do not need /type/123456/weqweqweqweqw/ these are more extra data which i dont need /';
console.log(str.match(/\/type\S+/));

它被标记为 Python,所以这是一个解决方案:

import re

re.search(r"/type/[^/]*/[^/]*/",str)
Out: <_sre.SRE_Match object; span=(39, 66), match='/type/123456/weqweqweqweqw/'>