简体   繁体   English

正则表达式匹配除字符组以外的所有字符

[英]Regex match all except groups of characters

I'm trying to match the following strings: 我正在尝试匹配以下字符串:

PHANTOGRAM • CUT / COPY • AB$SID 3 • FITZ & THE TANTRUMS
PHANTOGRAM,CUT / COPY,AB$SID 3,FITZ & THE TANTRUMS
PHANTOGRAM CUT / COPY AB$SID 3 FITZ & THE TANTRUMS

So, basically regex that matches anything between ( • |,| |\\n) . 因此,基本上正则表达式匹配( • |,| |\\n)之间的任何内容。

I have tried things like (([^•\\n])+) and positive lookahead, but geez I can't for the life of me put it together. 我已经尝试过(([^•\\n])+)和积极的前瞻性操作,但是geez我无法一辈子将它们组合在一起。 Any advice? 有什么建议吗? My hunch is I need a combination of positive lookahead and negative lookahead. 我的直觉是我需要将正面前瞻性和负面前瞻性结合起来。

Last note: this is for the javascript environment. 最后说明:这是针对javascript环境的。

Thanks for any help. 谢谢你的帮助。

Split should help you: 拆分应该可以帮助您:

var str = "PHANTOGRAM • CUT / COPY • AB$SID 3 • FITZ & THE TANTRUMS";
var res = str.split("•|,| |\n");

我最终使用了类似于laune的示例,但效果很好:

var matches = rawText.split(new RegExp(['\n', '•'].join('|'), 'g'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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