A
alainfri
I am not sure if this group is the right place for this question but
what I need is as follows. There is a piece of html. Throughout the
html there are a lot of <br> tags. The task is to replace all these
<br> tags with \n\r. The replacement must be performed only within
<pre> blocks. I can do this using VBScript in the following way:
Option Explicit
dim path2folder : path2folder = "D:\"
dim path2file : path2file = path2folder & "test.htm"
dim fileResults : fileResults = path2folder & "test-results.txt"
dim text
dim regex
Set regex = New RegExp
regex.Global = True
Dim regex1
Set regex1 = New RegExp
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
regex1.Global = True
Dim matches, match, tmp, tmp1
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim dfile : Set dfile = FSO.OpenTextFile( path2file, 1)
If dfile.AtEndOfLine <> True Then
text =dfile.ReadAll
dfile.Close
'///////////////////////////////////////////
' START OF RELEVANT CODE
regex.Pattern = "<pre>.*?<\/pre>"
Set matches = regex.Execute(text)
For Each match In matches
tmp = Match
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
tmp1 = regex1.Replace(tmp,vbCrlf)
text = Replace(text,tmp,tmp1)
Next
' END OF RELEVANT CODE
'///////////////////////////////////////////
Dim outfile : Set outfile = FSO.CreateTextFile(fileResults, True)
outfile.WriteLine text
outfile.Close
MsgBox "OK"
End If
The question is how to achieve the same results using one call of
regex.Replace, like
'THIS DOES NOT WORK
regex.Pattern = "(<pre>[.\n\r]*)(<[Bb][Rr][\/r]{0,1}>)([.\n\r]*</
pre>)"
text = regex.Replace(text, "$1" & vbCrlf & vbCrlf & "$3")
Than you.
what I need is as follows. There is a piece of html. Throughout the
html there are a lot of <br> tags. The task is to replace all these
<br> tags with \n\r. The replacement must be performed only within
<pre> blocks. I can do this using VBScript in the following way:
Option Explicit
dim path2folder : path2folder = "D:\"
dim path2file : path2file = path2folder & "test.htm"
dim fileResults : fileResults = path2folder & "test-results.txt"
dim text
dim regex
Set regex = New RegExp
regex.Global = True
Dim regex1
Set regex1 = New RegExp
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
regex1.Global = True
Dim matches, match, tmp, tmp1
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim dfile : Set dfile = FSO.OpenTextFile( path2file, 1)
If dfile.AtEndOfLine <> True Then
text =dfile.ReadAll
dfile.Close
'///////////////////////////////////////////
' START OF RELEVANT CODE
regex.Pattern = "<pre>.*?<\/pre>"
Set matches = regex.Execute(text)
For Each match In matches
tmp = Match
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
tmp1 = regex1.Replace(tmp,vbCrlf)
text = Replace(text,tmp,tmp1)
Next
' END OF RELEVANT CODE
'///////////////////////////////////////////
Dim outfile : Set outfile = FSO.CreateTextFile(fileResults, True)
outfile.WriteLine text
outfile.Close
MsgBox "OK"
End If
The question is how to achieve the same results using one call of
regex.Replace, like
'THIS DOES NOT WORK
regex.Pattern = "(<pre>[.\n\r]*)(<[Bb][Rr][\/r]{0,1}>)([.\n\r]*</
pre>)"
text = regex.Replace(text, "$1" & vbCrlf & vbCrlf & "$3")
Than you.