in reply to Re^2: Recursive Regex
in thread Parsing using Regex and Lookahead

So I'm thankful for the help!

First off: deMize « he »

Second, I'm not sure what I did was the best way of going about things. What I'm doing is just building a CMS insertion page with as little markup as possible, where each section is contained in it's own div.

Response:
The first problem was getting each into their own div, which the lookahead helped. To accomplish this, it just ends the current div when it hits a new section (may be a subsection in the future).

The reason for removing the line breaks was because I was using that as a delimiter for the last section --- there is probably a better way of doing that with determining the end of the string in the RegEx (maybe $), but I need to replace those line breaks with HTML breaks anyhow.

The problem:
This means that it is going to be linear with no sub-divs. I might have to rethink that for later, because I might want to have something like this later:
[section] [top]Top Data [middle]Mid Data [bottom]Bottom Data [section] [top]Top Data [bottom]Bottom Data

Should result to:
<div class="section"> <div class="top">Top Data</div> <div class="middle">Middle Data</div> <div class="bottom">Bottom Data</div> </div> <div class="section"> <div class="top">Top Data</div> <div class="bottom">Bottom Data</div> </div>

What I plan to do is store either the sub sections in an array or the sections in an array. I could probably use help with a better algorithm.
The whole purpose of this was so that I could quickly type the data into one input box, without building a whole intricate interface (that can come later).




Replies are listed 'Best First'.
Re^4: Recursive Regex
by furry_marmot (Pilgrim) on Mar 19, 2009 at 20:36 UTC

    What about something like:

    [section] top=Top Data middle=Mid Data bottom=Bottom Data [section] top=Top Data bottom=Bottom Data

    Now you've got a built-in qualitative difference that makes the parsing easier.