如何使用replace来删除js中的特定字符串

时间:2017-06-13 12:02:57

标签: javascript html replace

我有一个如下所示的字符串

<p class"font-size: 14px;text-align: justify;">Myeloid leukemia is a `cancer of the myeloid line of the blood cells. Put simple, it is when abnormal white blood cells build up in the bone marrow and interfere with the production of normal blood cells. Bone marrow over time is replaced with abnormal (cancer) cells, which leads to a drop in red blood cells, platelets, and normal white blood cells. As a result, patients suffering from myeloid leukemia can suffer from symptoms ranging from fatigue, bruising, bleeding, and an increase in the number of infections.</p><p class"font-size: 14px;text-align: justify;">There are two distinct types of <a href="https://www.xpertdox.com/disease-description/Leukemia" class"background-color: transparent;">myeloid leukemia</a>: acute myeloid leukemia (AML) and chronic myeloid leukemia (CML).</p><p class"font-size: 14px;text-align: justify;"><strong>How Leukemia Develops</strong></p><p class"font-size: 14px;text-align: justify;"><strong>Acute Myeloid Leukemia</strong></p><p class"font-size: 14px;text-align: justify;">This type of leukemia, also referred to as acute myelogenous leukemia, acute granulocytic leukemia, acute myeloblastic leukemia, or acute nonlymphocytic leukemia, is a cancer which grows quickly in the blood and bone marrow. Of all acute leukemia types, AML is the most common; it begins when a patient’s bone marrow produces cells which are not yet fully mature, called blasts. In normal circumstances, these cells would continue to develop and become white blood cells, but for those with AML, the cells do not mature and therefore cannot perform their job of fighting infection.</p><p class"font-size: 14px;text-align: justify;">Another possible problem for those with AML may be the production of irregular platelets and red blood cells by the bone marrow. These cells can rapidly overtake the number of properly functioning white and red blood cells and platelets necessary for a healthy body, making AML the more deadly of the two forms of myeloid leukemia.</p><p class"font-size: 14px;text-align: justify;"><strong>Chronic Myeloid Leukemia</strong></p>`

这里我要替换所有出现的class =&#34;&#34;为空,例如

 replace.('class"font-size: 14px;text-align: justify;','');

但是这里我有4个班级,但我知道只有班级才会开始,就像这个班级=&#34;并以&#34;结束。因此,我如何将所有类替换为空,以便

显示为

3 个答案:

答案 0 :(得分:0)

在jQuery中你可以使用它:

var string = '<p class"font-size: 14px;text-align: justify;">blah blah blah.......</p>';

/* this show only text without brackets and class name */
   var text = $(string).text();

答案 1 :(得分:0)

试试这个

var text = 'class="asdasd" class="123" class="zczxcz"'
text = text.replace(/"(.*?)"/g,'""')
console.log(text)

答案 2 :(得分:0)

您可以在此正则表达式中使用String.replace

str.replace(/class="[^"]*"/g,'class=""')

请注意,这假设您修复了&#39;类&#39; HTML中的属性包含等号。