[英]javascript capture substring of string using string matching and not indexes
[英]Capture matching text format in a string
我正在尝试编写一个正则表达式来提取以下文本中以#
开头并以)
结尾的项目
const bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)";
所以基本上,需要一个看起来像这样的数组:
["#[DataStructures](topic_DataStructures)", "#[Algorithms](topic_Algorithms)", "#[Make or Mar](topic_Make or Mar)"]
使用字符串match()
我们可以尝试:
var bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)"; var matches = bodyOfText.match(/#\[.*?\]\(.*?\)/g); console.log(matches);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.