You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用jQuery移除font-family中的"并保留其他引用符号?

Solution: Targeted Replacement with jQuery

Got it, let's tackle this problem step by step. You need to specifically remove the " entities that wrap font names in the font-family CSS property, while leaving identical entities in regular text (like vishal"s) untouched. Here's how to pull this off with jQuery:

Step-by-Step Implementation

Here's a straightforward jQuery snippet tailored to your needs:

// Get the raw HTML content from your text box (update the selector to match your element's ID/class)
var originalContent = $('#your-textbox-selector').val();

// Use a targeted regex to replace ONLY the " inside font-family declarations
var modifiedContent = originalContent.replace(/font-family:"([^&]+)"/g, 'font-family:$1');

// Push the cleaned content back into the text box
$('#your-textbox-selector').val(modifiedContent);

How the Regex Works

Let’s break down the regex to make sure you understand why it doesn’t affect your desired text:

  • font-family:": Explicitly targets the start of a font-family property with the opening escaped quote.
  • ([^&]+): Captures the actual font name (e.g., arial black) — this matches any characters except &, so it stops right before the closing ".
  • ": Matches the closing escaped quote for the font name.
  • The g flag ensures we replace every occurrence of this pattern in the content, not just the first one.

Example Test

If your original content is:

Hi this is vishal"s code <span style='font-family:"arial black"'>vishal</span>

After running the code, the processed content becomes:

Hi this is vishal"s code <span style='font-family:arial black'>vishal</span>

Exactly what you need — the " in vishal"s stays intact, while the ones wrapping arial black are removed cleanly.

Edge Case Handling

If your RadEditor sometimes uses double quotes for the style attribute (instead of single quotes) or adds whitespace after font-family:, adjust the regex to be more flexible:

var modifiedContent = originalContent.replace(/font-family:\s*"([^&]+)"/g, 'font-family:$1');

The \s* allows for optional spaces/tabs after font-family:, so the regex works even if the editor’s HTML formatting varies slightly.

内容的提问来源于stack exchange,提问作者user3844820

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:20:04