Javascript RegEx: Get all text matches surrounded by some other text? -


In Javascript / jquery, I want to get all the text that is seen between any other text. For example, if the HTML document was in:

  & lt; B class = "blah" & gt; Blast Some Lessons 1 & lt; / B & gt; & Lt; Div id = "foo" & gt; & Lt; B class = "blah" & gt; Blast: Some text 2 & lt; / B & gt;  

I want to get an array containing 'some text1' and 'some text2' because they are ' and lt; B class = "blah" in between & Gt; Blast: 'one' & lt; / B & gt; '

Since you mention jQuery, just select all the correct nodes and Check their text. If you want you can put a regx here, but it is not needed.

  & lt ;! DOCTYPE html public "- // W3C // DTD HTML 4.01 // EN http: //www.w3.org/TR/html4/strict.dtd"> & Lt; Html lang = "en" & gt; & Lt; Top & gt; & Lt; Title & gt; Trial & lt; / Title & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" & gt; & Lt; Script type = "text / javascript" src = "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Function () {var texts = []; $ ('b.blah'). (Function () {var txt = $ (this) .text (); if (0 == txt.indexOf ('Blah : ')) {Texts.push (txt.substr (6)}}}}); Warning (text);}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; B class = "blah" & gt; Blast Some Lessons 1 & lt; / B & gt; & Lt; Div id = "foo" & gt; & Lt; B class = "blah" & gt; Blast: Some text 2 & lt; / B & gt; & Lt; Div id = "foo" & gt; & Lt; B square = "blah" & gt; Some text 3 & lt; / B & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

or with a string of HTML

  $ (function () {var html = char = '& lt; b class = "blah" & gt; ; Blast some text 1 & lt; / b & gt; \ n '+' 
Blast some text 2 ; & Lt; / div & gt; \ n '+' & lt; div id = "foo2" & gt; & lt; b class = "blah" & gt; some text 3 & lt; / b & gt; Lt; / div> gt; var texts = []; $ ('b.blah', '& lt; (& quot;' + html chalk + ' gt;'). Function () {var txt = $ (this) .text (); if (0 == txt.indexOf ('blah' ')) {Texts.push (txt.substr (6))}}}); Warning ( Text);});

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -