[Jprogramming] Locate & Select
Raul Miller
rauldmiller at gmail.com
Thu Nov 25 01:50:58 HKT 2010
On Wed, Nov 24, 2010 at 12:18 PM, Chito Jovellanos
<chito at forwardlook.com> 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 at 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
More information about the Programming
mailing list