[英]Remove square brackets and their contents using jQuery + regexes
使用我在這里發現的示例,我試圖刪除由[
]
方括號包圍的文本的出現。
我的html中出現了[sample-text]
多次,並希望刪除整個內容,包括方括號。
我已經嘗試過了,但是不起作用-沒有東西被替換:
var replaced = $("body").html().replace(/^\[.*\]$/g,'');
$("body").html(replaced);
我正在嘗試使用[
開頭和以]
結尾匹配並刪除內部內容,但我無處可去。
var replaced = $("body").html().replace(/\[.*\]/g,'');
$("body").html(replaced);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.