Diane
Diane

Reputation: 3

Replace "+" in a csv file using VBScript

I'm looking to replace the symbol + in a CSV file. I'm using a VBScript run by another software.

I'm facing the error message "unexpected quantifier" 800A139A. However, the search and replace of # and e is working, and when I replace the research of + by research of -, it works. What could be the error?

Dim FILE1
Dim InFileName
Dim re
Dim reE
Dim reP

Set re = New RegExp
Set reE = New RegExp
Set reP = new RegExp
re.Pattern = "#"
reE.Pattern = "e"
reP.Pattern = "+"

re.Global = True
reE.Global = True
reP.Global = True

'Replace path and filename as required
'InFilename = "C:\" & Evoware.GetStringVariable("filename")
Set FILE1 = CreateObject("scripting.FileSystemObject")
Set infile = FILE1.OpenTextFile(InFileName, 1, False)

strg = infile.ReadAll
infile.Close

strg = re.Replace(strg, "")
strg = reE.Replace(strg, "")
strg = reP.Replace(strg, "")

MsgBox(strg)
Set Outfile = File1.CreateTextFile(inFileName, 1, False)
Outfile.Write(strg)

Upvotes: 0

Views: 445

Answers (1)

Mateus
Mateus

Reputation: 5372

I'm facing the error message "unexpected quantifier"

That is because the + symbol in regex represents a Greedy Quantifier. Which means one or more occurrences of the previous character/group. Example: a+ should match: a, aa, aaa...

If you want to use + as a literal character, your term should be escaped with a backslash.
To do that, simply replace "+" to "\+":

reP.Pattern = "\+"

Upvotes: 3

Related Questions