Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Jayson on November 08, 2019, 10:58:32 am
-
Hey all
I am using RegEx to find matches in string and then replace them.
The find match function seems to work, but the replace function does not.
I am using online generic VB Script language reference resources because I have never seen a Sparx specific one (might just never have seen it).
I am trying the following text and the output is "REGEX TEST = VAVAV", indicating that nothing has been replaced.
I have also tried the general string replace function and it doesn't seem to work either.
Any idea what my mistake is?
Cheers
Jays :-)
Dim regex1
Dim aString
aString = "VAVAV"
Set regex1 = new RegExp
regex1.Global = true
regex1.IgnoreCase = true
regex1.Pattern = "V"
regex1.Replace aString , "T"
Session.Output "REGEX TEST = '" & aString
-
You are not using Replace correctly.
Both the regular Replace, as the regex Replace don't change anything to the string passed as parameter.
They return a new string with the results.
Here's an example:
Function cleanFileName(fileName)
Dim regEx
Set regEx = CreateObject("VBScript.RegExp")
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "[(?*"",\\<>&#~%{}+@:\/!;]+"
cleanFileName = regEx.Replace(fileName, "-")
end function
Geert
-
Thanks Geert!
I always struggle with the fact that functions need brackets and subs don't, so I tried it as you described without the brackets and wondered what was going on!
All working now!
Cheers
Jays :-)