繁体   English   中英

捕获字符串中匹配的文本格式

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM