【发布时间】:2020-10-12 16:53:04
【问题描述】:
我想使用 Js 或 reactJS 替换或删除句子中的子字符串。
以下是我的例句。
RAND Corporation is an American nonprofit global policy think tank created in 1948 by Douglas Aircraft Company to offer research and analysis to the United States Armed Forces.
It is financed by the U.S. government and private endowment, corporations, universities and private individuals
Source: <Origin Href="Link">https://rand.org</a>
Thanks .....
在这句话中,我需要找到Source: <Origin Href="Link">https://rand.org</a>
所以基本上它会像 Source * </a> Source & </a> 将是其他句子中的常见字符串。 * 是通配符,可以包含其他各种文本。
那么,如何删除这一行或用空格或其他东西替换。
我当前的代码是
var sb = "RAND Corporation is an American nonprofit global policy think tank created in 1948 by Douglas Aircraft Company to offer research and analysis to the United States Armed Forces. It is financed by the U.S. government and private endowment, corporations, universities and private individuals Source: <Origin Href=\"Link\">https:\/\/rand.org</a> Thanks ..... "
var result = sb.replace(/\nSource:.*<\/a>/, '')
alert(result)
【问题讨论】:
-
正在调查。 .
标签: javascript reactjs regex