[英]Javascript regexp - remove space between quotation marks
i need to remove spaces just between quotation marks and just after style properties with regexp.我需要使用正则表达式删除引号之间和样式属性之后的空格。
before:前:
<h2><span style="font-family: Georgia; font-size: 10pt;">Text</span></h2>
after:后:
<h2><span style="font-family:Georgia; font-size:10pt;">Text</span></h2>
It's important for me because i need to convert html code to rtf file.这对我很重要,因为我需要将 html 代码转换为 rtf 文件。 Thanks for help感谢帮助
捕获包含空间的组的正则表达式如下所示:
".+?:(\s{1}).+?;"?
If you want remove inside the style attribute you can use the following code如果你想删除里面的样式属性,你可以使用下面的代码
m = data.replace(/style="(.+?)"/,($1)=>{
return $1.replace(/(?<=:)\s(?=\w)/g,'')
});
If you want replace anywhere in the string use following one如果您想替换字符串中的任何位置,请使用以下一个
m = data.replace(/(?:(?<=:)\s(?=\w)|(?<=;)\s)/g,'')
This may help you :这可能会帮助您:
(:\s)(?=(?:(?:[^"]*"){2})*[^"]*"[^"]*$)
It will capture all ": " (colon followed by a whitespace) that are between two " (doublequotes). Then you could replace them by a single colon, that should do what you wish.它将捕获两个“(双引号)之间的所有“:”(冒号后跟空格)。然后您可以用一个冒号替换它们,这应该可以满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.