Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

return match using regex


     I have been working on this for a few hours and am frustrated
beyond all extent.  I have tried to research this on the web as well
with no success.  I am trying to match certain contents within a
wrapper div.  So for example if the inside of the wrapper div was the

<div id="wrapper">
    <a href="#">a great link that contain text and symbols</a>
    <div> ... </div>
    <div> ... </div>

I would like to strip out all the internal div's.  But because there
can be alot of internal div's, I figured it would be less processor
intensive to just match the first 'a' tag and repopulate the wrapper
div with the match.  I am trying to use something like the following

re = /^<a(.+)</a>/;

with the following statment:

$temp = document.getElementById('wrapper').innerHTML.match(re);

but this is returning the entire contents of the wrapper div.  I have
tried variations of the regex and either continue to get the entire
contents or null returns.  Any help would greatly be appreciated.
BTW, I can't match to the first \n because the contents may be
touching (ie ...</a><div>...).


On May 18, 11:24 am, hende@gmail.com wrote:

I'm not a big fan of using regexps for parsing HTML.
Getting a bulletproof expression is a major pain.

For example, here's one from 'Mastering Regular
Expressions 2nd edition' by J. Friedl (publisher
O'Reilly) for matching HTML tags:


How about...

var container=document.getElementById('wrapper');
var list=[];
 if(!('tagName' in container.lastChild)||




It does a little extra work to avoid
the nastiness of dealing with indexing
into a list that's being resized.


On May 18, 1:19 pm, Geoffrey Summerhayes <sumr@gmail.com> wrote:


     Thanks for the reply.  I was looking for something less processor
intensive.  The inner div's can be in the hundreds.  Thats why I was
looking at just isolating the first href tag and replacing the entire
contents of the wrapper div.  Any other thoughts would be appreciated.


On May 18, 1:36 pm, hende@gmail.com wrote:


     I was getting nowhere trying to use regex's, so I just decided to
use a combination of substring's and indexOf's.  Everything seems to
be working beautifully.  Thanks anyways.


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc