Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Concatenate two regular expression in Javascript

I want to concatenate two reqexp while replace process. Its working fine one by one replace. Please guide.

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, "");

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Maybe using a OR (|) operator:

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

Hope this helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading