例如:
我想要得到 *created by:*
和 *M*
并且不要得到 *proudly *
或 *自豪*
( *
或 *
附近有空格)与 javascript 中的正则表达式。
//not work
let c = "RegExr was *created by:* gskinner.com, and is *proudly *hosted by *M*edia Temple.";
const regExr = /(\*\*)([^\s|\*])+([^\s|\*])(\*\*)/g;
这项工作(tnx for @Wiktor Stribiżew
)
const regExr = /\*([^*]*[^*\s])\*/g;
但不工作:*自豪地*
我改为 -> /\*([^*\s]*[^*\s])\*/g
但不要得到 -> *创建者:*
最佳答案
首先,match *
和 filter 之间的所有结果最后一个之前不包含空格的结果 (*
)
let c ="RegExr was *created by:* gskinner.com, and is *proudly *hosted by *M*edia Temple.";
const regExr = /(\*)(.+?)\1/g;
const result = c.match(regExr).filter((el) => !el.match(/\*.+\s\*/));
console.log(result);
关于javascript - 使用正则表达式获取两个没有空格的空间字符之间的一些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67672139/