On Wed, Nov 24, 2010 at 12:18 PM, Chito Jovellanos
<[email protected]> wrote:
> I'm trying to find an expression that will return the text between two
> adjacent html tags (with each occurrence boxed).  In the sample snippet
> below, I want to retrieve the text between <span class="Header2">  and the
> next instance of </span> which should yield a boxed list containing four
> instances of  the text string 'core.contains'.

html is tricky, since it is almost like xml but it can also be a mess
sometimes.

Personally, I tend to prefer regular expressions, when I can get away
with it, because I can deal with them easier, when I encounter html
that is not valid xml.

Here is a regular expression implementation of what I think you are asking for:

   require'regex'
   ({:"2 '(?i)<span[^<>]*class="Header2"[^<>]*>(.*?)</span>' rxmatches
html) rxfrom html

This assumes that the variable 'html' holds the content you posted in your
message.

If you want that expressed more tacitly (only one reference to the html):
   (rxfrom~ 
{:"2...@rxmatches~&'(?i)<span[^<>]*class="Header2"[^<>]*>(.*?)</span>')
html

See also:
http://www.jsoftware.com/help/pcre/index.html
http://www.jsoftware.com/jwiki/Studio/Regular%20Expressions
http://perldoc.perl.org/perlre.html

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to