I’m having some strange behavior working with Regular Expressions.
I have the following code:
[code]Public Function ToJSONEscapedText(extends x as XmlDocument) as Text
Dim contents As String = x.ToString
//Carriage Return Is replaced With \r
Dim re As New RegEx
re.SearchPattern = “\r”
re.ReplacementPattern = “\\r”
re.Options.ReplaceAllMatches = True
Dim m As RegExMatch = re.Search( contents )
Dim output As String = re.Replace
contents = output
//Double quote Is replaced With "
re = New RegEx
re.SearchPattern = “”""
re.ReplacementPattern = “”""
re.Options.ReplaceAllMatches = True
output = re.Replace( contents )
contents = output
//Backslash Is replaced With \\
re = New RegEx
re.SearchPattern = “\”
re.ReplacementPattern = “\\\”
re.Options.ReplaceAllMatches = True
output = re.Replace( contents )
contents = output
Return contents.DefineEncoding( Encodings.UTF8 ).ToText
End Function
[/code]
When using the above regular expressions in RegEx Tester they work no problem, but in Xojo nothing is matched or replaced when using the below XML (pulled from the XMLDocument page in the docs):
<?xml version="1.0" encoding="UTF-8"?>
<League>
<Team name="Seagulls">
<Player name="Bob" position="1B" />
<Player name="Tom" position="2B" />
</Team>
<Team name="Pigeons">
<Player name="Bill" position="1B" />
<Player name="Tim" position="2B" />
</Team>
<Team name="Crows">
<Player name="Ben" position="1B" />
<Player name="Ty" position="2B" />
</Team>
</League>
To make things even more strange, I was initially testing this out in a Web App but couldn’t even instantiate the XML. I kept getting a Parser Error 2: Syntax Error. I did double check that this XML is valid using an online validator which didn’t report any problems.
Does there appear to be anything wrong with my code or with this XML before I file bug reports?