如何删除[和]以及其间的任何内容(javascript)

如何删除[和]以及其间的任何内容(javascript),javascript,arrays,string,Javascript,Arrays,String,如果内容仅包含一个数字,如何删除“[”和“]”以及介于两者之间的内容 起始字符串: let cityInfo = "Munich (/ˈmjuːnɪk/ MEW-nik; German: München [ˈmʏnçn̩] (listen);[3] Austro-Bavarian: Minga [ˈmɪŋ(ː)ɐ]; Latin: Monachium) is the capital and most populous city of Bavaria. With a population of a

如果内容仅包含一个数字,如何删除“[”和“]”以及介于两者之间的内容

起始字符串:

let cityInfo = "Munich (/ˈmjuːnɪk/ MEW-nik; German: München [ˈmʏnçn̩] (listen);[3] Austro-Bavarian: Minga [ˈmɪŋ(ː)ɐ]; Latin: Monachium) is the capital and most populous city of Bavaria. With a population of around 1.5 million,[4] it is the third-largest city in Germany."
“[]”之间的一些信息需要保留。示例:[mʏnçn̩]和[mɪ331;(ː)ɐ] 我需要去掉一些。示例:[3]和[4]

如何循环遍历字符串,删除包含数字的括号,而保留不包含数字的括号

期望输出: “慕尼黑(/mjuɪnɪk/MEW nik;德语:慕尼黑[MˈMʏnçn̩](听着);奥斯特罗-巴伐利亚州:明加[MɪMɪ(ɪ)k/MEW nik]是巴伐利亚州的首府和人口最多的城市。该市人口约150万,是德国第三大城市。”

我在网上查阅了几份参考资料,但我找到的所有参考资料似乎都没有为我正在尝试做的事情提供解决方案。不起作用的示例: --- --- --- ---

您可以使用正则表达式
/\[\d+\]/g
匹配方括号内的所有数字序列,然后用空字符串(
'
)替换:

慕尼黑:慕尼黑是巴伐利亚州的首府和人口最多的城市,人口约150万,是德国第三大城市; const res=cityInfo.replace(/\[\d+\]/g'); 控制台日志(res)您可以使用正则表达式
/\[\d+\]/g
匹配方括号内的所有数字序列,然后用空字符串(
'
)替换:

慕尼黑:慕尼黑是巴伐利亚州的首府和人口最多的城市,人口约150万,是德国第三大城市; const res=cityInfo.replace(/\[\d+\]/g');
控制台日志(res)数字是随机的?是的-我不知道之前的数字是什么?是的-我不知道之前的数字是什么