On Tue, Jan 27, 2009 at 8:17 PM, Francis Fish <[email protected]>wrote:

> On Tue, Jan 27, 2009 at 5:04 PM, Adam Holt <[email protected]> wrote:
>
>> Hi guys,
>>
>> I'm having some trouble figuring out how to do some regular expression
>> foo and thought maybe someone on here could help,
>>
>> Basically i am trying to parse out special tags from html returned
>> from TinyMCE, and replace them with content for doing html to pdf
>> generation.
>>
>> I've written a little gist page demonstrating what i need it to do:
>> http://gist.github.com/53383
>>
>> i have got it working so far with 1 paragraph inside the if statement
>> (the first example), but when you have two content paragraphs, it
>> fails to match.
>>
>> i have written some rspec tests for it, if anyone fancies having a go,
>> i've included my current regular expression, if you want to build on
>> that :)
>>
>> Cheers,
>> Adam
>>
>>  I got the attachments ok on gmail ...
>
> just to make sure, why would you have the meta stuff inside <p> tags?? If
> you do some kind of replace you'll just end up with empty <p></p> when it's
> parsed?? Is that what's intended??
>
> /<([^>]*)>.*<\/\1>/
>
> I tend to construct regexps saying what I don't want - here I'm saying I
> don't want the closing >, then I'm reusing the first regexp again in the
> expression
>
> Now we want the {{ thing to replace the .*
>
> Let's just find if first
>
> /\{\{[^}]*if[^}]*\}\}/
>
> if followed by anything that isn't a closing brace
>
> Now find end
>
> /\{\{[^}]*end[^}]*\}\}/
>
> Inject this into our regexp (gonna use 'x' mode to make it clear)
>
>   /
> <([^>]*)>                 # open tag
> \{\{[^}]*if[^}]*\}\}      # if
> <\/\1>                    # close tag
> .*                        # any thing you like
> <\1>                      # open same tag
> \{\{[^}]*end[^}]*\}\}     # end
> <\/\1>?                   # close tag
> /xm                       # m means multiline no need for those ugly \r \n
> thangs
>
> This will not work when you have several if's one after the other because
> it will greedily match the last end and ignore the first one as per your
> last test
>
> I went for the non-greedy version of the matches
> /
> <([^>]*)>                 # open tag
> \{\{[^}]*if[^}]*\}\}      # if
> <\/\1>                    # close tag
> .?                        # non-greedy any thing you like
> (<\1>                     # open same tag
> \{\{[^}]*end[^}]*\}\}     # end
> <\/\1>)?                  # non-greedy close tag and end
> /xm                       # m means multiline no need for those ugly \r \n
> thangs
>
> This finds two as expected, but doesn't give the string you wanted back.
> Lost the will to live now...
>
> HTH
>
>
> --
> Thanks and regards,
>
> Francis Fish
>

I tried bracketing the whole thing and got more in the match, but still not
all of it.

-- 
Thanks and regards,

Francis Fish

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nwrug-members?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to