javascript - Little regular expression on js -


i new in regular expressions. have variable contains:

<b><font color="#32748">my string:</font></b> <big>  value </big> <br> 

its string in varible repeating multiple times changing of my string , my value(random value). need find my value of concrete my string , store (value) in new varible. string has spaces, without space.

you should try avoid using regular expressions parsing html. powerful tools built right every browser.

here solution no regular expressions, find pretty simple.

here how works:

  • we create html element
  • the browser contains html parser :) handles edge cases spaces in name, escaped entities, , partial html web pages. dump html in element.
  • we can query element using queryselector syntax, or simpler getelementsbytagname if you're old fashined guy.
  • we use textcontent property obtain text.

actual code:

var test = '<b><font color="#32748">my string:</font></b><big>  value </big><br>';  // create empty element , put html in var div = document.createelement("div"); div.innerhtml = test;  // text font tag, asked for. var test = div.queryselector("font").textcontent;  

fiddle

note, <font> tags deprecated , should not used in new code. i'd consider checking out current html5 spec , seeing how things work in modern html.

note2, in oldie can't use textcontent can innerhtml or innertext.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -