[英]How do I remove the string in brackets only from the beginning of the entire string?
我嘗試使用replace刪除括號中的字符串。 但這不起作用。 我只想刪除開頭的括號。
var string="(I want to delete this) helloo (not this)";
var replacedString=string.replace(/ *\([^)]*\) */g, "");
您可以在字符串的開頭查找第一個括號,並在字符串的結尾查找括號,然后替換它。
var string = "(I want to delete this) helloo (not this)", result = string.replace(/^\\([^)]*\\)/, ''); console.log(result);
這應該在大多數(如果不是全部)實例中起作用:
myString.replace(/\\((.*?)\\)/, '$1')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.