[英]Regex select specific characters between double quotes
I would like to extract specific character ie ;
我想提取特定的字符,即
;
that are located between quotes ( "
) with a Regex expression.用正则表达式位于引号 (
"
) 之间。
String example :字符串示例:
Lorem;ipsum;"dolor;sit;";amet;
Lorem;ipsum;"dolor;sit;";amet;
Should select every ;
应该选择每一个
;
in quotes :在引号中:
Lorem;ipsum;"dolor
;
sit;
";amet;Lorem;ipsum;"dolor
;
坐;
";amet;
I tried this one but it doesn't work我试过这个,但它不起作用
(?<=\")(;)*(?=\")
Any idea ?任何的想法 ? Thank you in advance
先感谢您
You will have to do it in two steps:您必须分两步完成:
/"[^"]+"/gm
/"[^"]+"/gm
;
;
you should be able to use String.prototype.replace
with the given regex and look for ";"您应该能够将
String.prototype.replace
与给定的正则表达式一起使用并查找“;” in your replace callback.在您的替换回调中。
here is a demo:这是一个演示:
function escapeCsvDelimiter(input) { return input.replace(/"[^"]+"/gm, (match) => match.replace(/;/g, '\\\\;')); } const test = 'Lorem;ipsum;"dolor;sit;";amet;"jhv;"'; const result = escapeCsvDelimiter(test); console.log(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.