Suppression with Regular Expression
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2010
08:11 PM
07-07-2010
08:11 PM
Suppression with Regular Expression
I have an XML file and I want to delete
everything that is between 2 tags including the tags.
<M_CODE>
<src>
...
</ SRC>
</ M_CODE>
I wanted to use the
Replace command but I can not use a regular expression
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 1)
strText = objFile.ReadAll
objFile.Close
RegExpr = "^<M_CODE>(.+)</M_CODE>$"
strNewText = Replace(strText, RegExpr, "")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 2)
objFile.WriteLine strNewText
objFile.Close
or
should I do otherwise?
everything that is between 2 tags including the tags.
<M_CODE>
<src>
...
</ SRC>
</ M_CODE>
I wanted to use the
Replace command but I can not use a regular expression
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 1)
strText = objFile.ReadAll
objFile.Close
RegExpr = "^<M_CODE>(.+)</M_CODE>$"
strNewText = Replace(strText, RegExpr, "")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 2)
objFile.WriteLine strNewText
objFile.Close
or
should I do otherwise?
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2010
10:27 PM
07-07-2010
10:27 PM
Hi Christophe,
The variant you offered is incorrect. Here is an example demonstrating how to do this:
Sub Main
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Test\File.XML", 1)
strText = objFile.ReadAll
objFile.Close
Log.Message(strText)
Set RegExpr1 = HISUtils.RegExpr
' Note that the ^ and $ symbols have been removed
RegExpr1.Expression = "<M_CODE>(.+)</M_CODE>"
strNewText = RegExpr1.Replace(strText, "")
Log.Message(strNewText)
Set objFile = objFSO.OpenTextFile("C:\Test\File.XML", 2)
objFile.WriteLine strNewText
objFile.Close
End Sub
Does it help you?
-----
Alexander
Customer Care Manager
Alexander
Customer Care Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2010
10:31 PM
07-07-2010
10:31 PM
I found
the solution to my problem :
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 1)
strText = objFile.ReadAll
objFile.Close
Set RegExM = New RegExp
RegExM.Pattern = "<M_CODE>[\s\S]+</M_CODE>"
RegExM.Global = True
strNewTextM = RegExM.Replace(strText, "")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 2)
objFile.WriteLine strNewTextM
objFile.Close
the solution to my problem :
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 1)
strText = objFile.ReadAll
objFile.Close
Set RegExM = New RegExp
RegExM.Pattern = "<M_CODE>[\s\S]+</M_CODE>"
RegExM.Global = True
strNewTextM = RegExM.Replace(strText, "")
Set objFile = objFSO.OpenTextFile("C:\Users\TestAdmin\Desktop\Essai.XML", 2)
objFile.WriteLine strNewTextM
objFile.Close
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2010
10:34 PM
07-07-2010
10:34 PM
Thank you Alex AQA
