gpt4 book ai didi

javascript - 使用 Javascript 删除括号和文本

转载 作者:行者123 更新时间:2023-11-30 10:33:15 26 4
gpt4 key购买 nike

我有一个长字符串,有许多不同的方括号/大括号/圆括号 ({{...}},{...},[...], [[...]], <...> ),有些在其他内部。

我想使用 JS 删除这些括号以及其中的任何文本/等(除了 [[...]] 不在其他括号内,在这种情况下我只想删除括号)。

这是我正在使用的字符串类型的示例:

{{pp-move-indef}} {{Taxobox | name = Red panda | status = VU | status_system = iucn3.1 | status_ref = | image = RedPandaFullBody.JPG | regnum = [[Animal]]ia | phylum = [[Chordate|Chordata]] | classis = [[Mammal]]ia | ordo = [[Carnivora]] | subordo = [[Caniformia]] | infraordo = [[Arctoidea]] | superfamilia = [[Musteloidea]] | familia = [[Ailuridae]] | genus = Ailurus | genus_authority = [[Frederic Cuvier|F. Cuvier]], 1825 | species = A. fulgens | binomial = Ailurus fulgens | binomial_authority = [[Frederic Cuvier|F. Cuvier]], 1825 | range_map = Cypron-Range Ailurus fulgens.svg | range_map_caption = Red panda range | subdivision_ranks = Subspecies | subdivision = A. f. fulgens
A. f. styani }}

The red panda (Ailurus fulgens, lit. "shining cat"), is a small [[arboreal]] [[mammal]] native to the eastern [[Himalayas]] and southwestern [[China]]{{IUCN |assessors=Wang, X., Choudhry, A., Yonzon, P., Wozencraft, C., Than Z. |year=2008 |id=714 |taxon=Ailurus fulgens |version=2010.4 |downloaded=26 June 2010}} and related to [[raccoon]]s, [[skunk]]s and [[weasel]]s. It is the only extant species of the genus Ailurus and the family [[Ailuridae]]. Slightly larger than a [[domestic cat]], it has reddish-brown fur, a long, shaggy tail, and a waddling gait due to its shorter front legs. It feeds mainly on [[Bamboo shoot|bamboo]], but is [[omnivorous]] and may also eat eggs, [[bird]]s, [[insect]]s, and small [[mammal]]s. It is a [[solitary animal]], mainly [[Nocturnality|active from dusk to dawn]], and is largely [[Sedentary lifestyle|sedentary]] during the day.

期望的结果

The red panda (Ailurus fulgens, lit. "shining cat"), is a small arboreal mammal native to the eastern Himalayas and southwestern China and related to raccoons, skunks and weasels. It is the only extant species of the genus Ailurus and the family Ailuridae. Slightly larger than a domestic cat, it has reddish-brown fur, a long, shaggy tail, and a waddling gait due to its shorter front legs. It feeds mainly on Bamboo shoot|bamboo, but is omnivorous and may also eat eggs, birds, insects, and small mammals. It is a solitary animal, mainly Nocturnality|active from dusk to dawn, and is largely Sedentary lifestyle|sedentary during the day.

最佳答案

function removeBrackets(input) {
return input
.replace(/{.*?}/g, "")
.replace(/\[.*?\]/g, "")
.replace(/<.*?>/g, "")
.replace(/\(.*?\)/g, "");
}

关于javascript - 使用 Javascript 删除括号和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15594495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com