字符串解析并生成新的搜索数组



我从后端得到这样的字符串(im使用<pre></pre>按照后端数据库中的方式格式化(:

Main responsibilities will include:
- Driving creation of customer attractive brand
- Making a significant impact on lead generation and quality of the incoming pipeline
- Creating marketing materials (Company overview, Company presentation, Case studies, Brochure, Video)
- Online Advertisement

我试图解析这个字符串,并将所有-东西(从"-"开始的字符串(放入这些项的一个数组中。所以我需要得到

let arr = ["Driving creation of customer attractive brand", "Making a significant impact on lead generation and quality of the incoming pipeline", "...", "Online Advertisement"]

如何才能做到这一点,有什么想法吗?

您可以遵循以下示例:

const str = `Main responsibilities will include:
- Driving creation of customer attractive brand
- Making a significant impact on lead generation and quality of the incoming pipeline
- Creating marketing materials (Company overview, Company presentation, Case studies, Brochure, Video)
- Online Advertisement`;
let regex = /(?<=^s-s).*/gm;
let match = str.match(regex);
console.log(match);

regex101中的详细信息:https://regex101.com/r/xdyCzO/1
一些注意事项:
(?<=^s-s)=正向回溯,它获取每个句子的-开头之后的所有内容(\s=1空格,^=行的开头(
.*=除换行符外的任何字符,*表示零或更多

最新更新