Strip <?xml and <!DOCTYPE from string
stripe meaning
strip python
how to pronounce strip
strip of paper
striped
stripes definition
strip meaning hindi
I have the following string in Javascript and need to remove the <?xml ... ?>
and <!DOCTYPE .... ]>
tags. Can not convert it to a dom because the BR tags error as not being closed - and not able to edit the actual content.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp "&#38;">]><div>Blah<br> Blah</div>
Trying to do it with .replace but can't quite seem to get there
text.replace(/\<\?xml.+\?\>/g, '');
Your replace()
works for the <?xml ... ?>
part.
To remove the <!DOCTYPE .... ]>
part as well you can do:
text.replace(/\<\?xml.+\?\>|\<\!DOCTYPE.+]\>/g, '');
As you can see here: http://jsfiddle.net/darkajax/9fKnd/1/
Strip, strip meaning: 1. to remove, pull, or tear the covering or outer layer from something: 2. to remove your…. Learn more. a narrow piece, comparatively long and usually of uniform width: a strip of cloth, metal, land, etc. a continuous series of drawings or pictures illustrating incidents, conversation, etc., as a comic strip.
you can use this regex:
text.replace(/\<(\?xml|(\!DOCTYPE[^\>\[]+(\[[^\]]+)?))+[^>]+\>/g, '');
that works with :
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp "&#38;">]><div>Blah<br> Blah</div> <?xml version="1.0" encoding="UTF-8"?><div>Blah<br> Blah</div> <!DOCTYPE html [<!ENTITY amp "&#38;">]><div>Blah<br> Blah</div>
STRIP, (television) A television series aired at the same time daily (or at least on Mondays to Fridays), so that it appears as a strip straight across the weekly schedule. to remove, pull, or tear the covering or outer layer from something: Because of the pollution, the trees are almost completely stripped of bark. The paintwork was so bad that we decided to strip off all the paint and start again. [ + adj ] During the summer months, the sheep strip the mountains bare.
The accepted answer has unnecessary escaping (extra back slashes, making an ugly regex uglier), this works too:
const text = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp "&#38;">]><div>Blah<br> Blah</div>' console.log(text) const afterReplace = text.replace(/<\?xml.+\?>|<!DOCTYPE.+]>/g, '') console.log(afterReplace)
strip, The verb strip has many shades of meaning, but most of them involve removing something. Someone may strip you of your power or you may strip off your A strip is a long street in a city or town, where there are a lot of stores, restaurants, and hotels.
strip, Strip or Stripping may refer to: Contents. 1 Places; 2 Arts, entertainment, and media. 2.1 Comics; 2.2 Erotic dancing; 2.3 Films; 2.4 Music; 2.5 Television. 14 synonyms of strip from the Merriam-Webster Thesaurus, plus 35 related words, definitions, and antonyms. Find another word for strip.
Strip, Middle English (as a verb): of Germanic origin; related to Dutch stropen. strip (sense 2 of the noun) arose in the late 20th century, possibly from the notion of A strip is a bond coupon that has been removed from the bond so that the two parts can be sold separately, as an interest-paying coupon bond and as a zero-coupon bond. This process is handled by
Strip, New Covid-19 clusters have been found in a Pentecostal church in Oregon, a strip club in Wisconsin and in every imaginable place in between. Song Strip; Artist Little Mix; Licensed to YouTube by SME (on behalf of Syco Music); Abramus Digital, UMPI, CMRRA, LatinAutor - PeerMusic, LatinAutor - SonyATV, ARESA, ASCAP, UNIAO BRASILEIRA DE
Comments
- So, what advantage does it offer over darkajax's answer from 8 minutes ago?
- I'm more generic. If the content changes my regex continues to work.