在JavaScript中连接两个正则表达式

dzjeubhm  于 2023-08-02  发布在  Java
关注(0)|答案(1)|浏览(86)

我想连接两个reqexp while replace进程。它的工作很好,一个接一个地更换。请引导。

var content = `series onPsychologyOutlineHistorySubfields<button type="button" class="mw-collapsible-toggle mw-collapsible-toggle-default" aria-expanded="true" tabindex="0">hide</button>Basic typesAbnormalBehavioralBehavioral geneticsBiologicalCognitive/CognitivismComparativeCross-culturalCulturalDevelopmentalDifferentialEvolutionaryExperimentalMathematicalNeuropsychologyPersonalityPositivePsychodynamicPsychometricsQuantitativeSocial<button type="button" class="mw-collapsible-toggle mw-collapsible-toggle-default" aria-expanded="true" tabindex="0">hide</button>Applied psychologyApplied behavior analysisClinicalCommunityConsumerCounselingCriticalEducationalEnvironmentalErgonomicsFoodForensicHealthHumanisticIndustrial and organizationalLegalMedicalMilitaryMusicOccupational healthPoliticalPsychometricsReligionSchoolSportTraffic<button type="button" class="mw-collapsible-toggle mw-collapsible-toggle-default" aria-expanded="true" tabindex="0">hide</button>ListsDisciplinesOrganizationsPsychologistsPsychotherapiesResearch methodsTheoriesTimelineTopics<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Psi2.svg/16px-Psi2.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Psi2.svg/24px-Psi2.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Psi2.svg/32px-Psi2.svg.png 2x" data-file-width="100" data-file-height="100"> Psychology portalvte<p><b>Psychology</b> is the study of mind and behavior in humans and non-humans. Psychology includes the study of</p>`;

var regex1= /(<([^>]+)>)/ig;
var reqex2= /<img[^>]*>/g;

content = content.replace(regex1, "");

content = content.replace(regex2, "");

字符串

gab6jxml

gab6jxml1#

可以使用OR(|)运算符:

var content = "Your big thing"
var regex = /(<([^>]+)>)|(<img[^>]*>)/ig;
content = content.replace(regex, "");

字符串
希望这对你有帮助!

相关问题