正则表达式匹配除给定前缀之外的任何字符

Regex match any character except given prefix

我正在寻找一个标题为 can do 的正则表达式模式,这意味着有 3 个给定的前缀“#、@、+”,后面的字符将被忽略,直到它变成空白。示例:

"+20 @facebook #hashtag with my love"

将return

"with my love"

您可以通过以下方式使用它

const regex = /[\+|\@|\#][\w\p{P}]*\s+/g;
const str = '"+20 @facebook #hashtag with my love"';
const subst = '';

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log('Substitution result: ', result);

看看https://regex101.com/r/K1YQQZ/1