Find / replace a line that spans lines in a file with REBOL

I have an HTML page and I need to replace a couple of lines. However, use replacecannot find anything more than one line.

This is what I would like to replace (there are several instances on the page):

....
<div class="logo">
    <img src="resources/logo.svg" />
    <span>e</span>
    <span class="text">Market</span>
</div>
...

Here's the code I'm trying, but it doesn't work:

index-html: read %index.html    

logo-div: {<div class="logo">
<img src="resources/logo.svg" />
<span>e</span>
<span class="text">Market</span>
</div>}

new-div: {...}

out: replace/all index-html logo-div new-div

write %index.html out

Inclusion ^/in a line logo-divto indicate translation lines does not help.

How can I find this whole line?

(I use Rebol2, but I assume that the functionality will be the same or very similar in Rebol3.)

+4
source share
2 answers

replace, parse :

index-html: read %index.html
out: copy ""
new-div: "..."

;;parse rules

title: [
    {<div class="logo">} thru {</div>} (append out new-div) ;;appends replacement when it finds that class
]

rule: [
    some [
        title |
        copy char skip (append out char)  ;;copies every other char char
    ]
]

parse index-html rule

write %index.html out

, . . .

+4

, , , - . , :

>> data: {
{    line 1     
{    line 2  
{    line 3
{    line 4   
{    <div>
{    line d1   
{    line d2
{    </div>
{    line 5    
{    line 6                   
{    }
== {
line 1     
line 2  
line 3
line 4   
<div>
line d1   
line d2
</div>
line 5    
line 6                   
}
old-div: {                
{    <div>
{    line d1   
{    line d2
{    </div>
{    }
== {
<div>
line d1   
line d2
</div>
}
>> new-div: {
{    <div>new line d1^/new line d2</div>
{    }
== "^/<div>new line d1^/new line d2</div>^/"
>> replace/all trim/all data trim/all old-div new-div
== {line1line2line3line4
<div>new line d1
new line d2</div>
line5line6}
>> data
== {line1line2line3line4
<div>new line d1
new line d2</div>
line5line6}

HTML, , kealist, , .

+2

All Articles