下面的@ font-face CSS指令在IE 11中不起作用,除非font-family手动用双引号括起来,这是我想要使用正则表达式进行自动化的。到目前为止,我已经接近但是很难检测匹配的字符串是否有引号。
'@font-face {font-style: normal;font-family: f11;font-variant: normal;font-weight: normal; }'.replace(/font-family\:(.*?)\;/, "font-family: \"$1\";");
如果你在控制台中运行以下字符串,你会看到,
@font-face {font-style: normal;font-family: " f11";font-variant: normal;font-weight: normal; }
我想做的两件事:
<SPACE>f11
。答案 0 :(得分:1)
replace(/font-family:\s*([^"]+?);/, "font-family: \"$1\";")
解决了#1和#2。
'@font-face {font-style: normal;font-family: f11;font-variant: normal;font-weight: normal; }'.replace(/font-family:\s*([^"]+?);/, "font-family: \"$1\";");
↓
@font-face {font-style: normal;font-family: "f11";font-variant: normal;font-weight: normal; }
如果已经引用:
'@font-face {font-style: normal;font-family: "f11";font-variant: normal;font-weight: normal; }'.replace(/font-family:\s*([^"]+?);/, "font-family: \"$1\";");
↓
@font-face {font-style: normal;font-family: "f11";font-variant: normal;font-weight: normal; }