Hi Rick, what I understood, its the opposite, RegEx is used for compact and fast like [^0-9a-zA-Z:,]+", “”
I know that, but I think that Xojo regex is not exactly equivalent.
The Xojo RegEx class seems equivalent, only issue I have is the ü kind of characters.
I’m curious… it looks like you’re trying to strip the encoding from the string. If so, have you tried just setting the encoding to ASCII or Nil using ConvertEncoding?
So, just do it… in Xojo:
let str = "ä...ö...ü...©";
const mapObj = {
'ä': "ae",
'ö': "oe",
'ü': "ue",
'©': "c"
};
str = str.replace(/(?:ä|ö|ü|©)/gi, matched => mapObj[matched]);
Xojo has
regex.Replace(stringToGetReplacements As String) As String
Maybe you could make a Feature Request to get another signature:
regex.Replace(stringToGetReplacements As String, match As RegExReplaceFunction) As String
Public Delegate Function RegExReplaceFunction(match As String) As String
Xojo makes it simple:
Var re As New RegEx
var newText as String
re.SearchPattern = ComboBoxRegEx.Text
re.ReplacementPattern = TextFieldRegExReplace.Text
newText = re.Replace(s)
My problem is the ü kind of characters, they are ignored…
It does just ONE of your list of chars to be replaced each turn as ReplaceAll
You are building a huge and costly ReplaceAll.
This will enable building what you want
replaceAll is a standard RegEx option
re.Options.ReplaceAllMatches=Preferences.RegExReplaceAll
Here it simply does not work. I. think the ü issue in RegEx is connected to macOS. [Edit: not true, it does work, but not in a more complex code setting…]
Wrong: Rich two lines example works fine here with Xojo 2021r2.1 / Ventura 13.1…
You are right, I just changed my post about it.
The stripped code indeed works fine, but this does not, were s as string:
Var re As New RegEx
re.SearchPattern = ComboBoxRegEx.Text
re.ReplacementPattern = TextFieldRegExReplace.Text
re.Options.CaseSensitive=Preferences.RegExCase
re.Options.Greedy=Preferences.RegExGreedy
re.Options.ReplaceAllMatches=Preferences.RegExReplaceAll
Try
s = re.Replace(s)
RoundRectangleRegEx.Visible=False
Catch err As OutOfBoundsException
RoundRectangleRegEx.Visible=True
Catch err As RegExSearchPatternException
RoundRectangleRegEx.Visible=True
end Try
Return s
Function removeAccents(inputString As String) As String
Dim outputString As String = inputString
Dim accentMapping() As String = {"À", "A", "Á", "A", "Â", "A", "Ã", "A", "Ä", "A", "Å", "A", "à", "a", "á", "a", "â", "a", "ã", "a", "ä", "a", "å", "a", "È", "E", "É", "E", "Ê", "E", "Ë", "E", "è", "e", "é", "e", "ê", "e", "ë", "e", "Ì", "I", "Í", "I", "Î", "I", "Ï", "I", "ì", "i", "í", "i", "î", "i", "ï", "i", "Ò", "O", "Ó", "O", "Ô", "O", "Õ", "O", "Ö", "O", "Ø", "O", "ò", "o", "ó", "o", "ô", "o", "õ", "o", "ö", "o", "ø", "o", "Ù", "U", "Ú", "U", "Û", "U"}
For i As Integer = 0 To accentMapping.Ubound Step 2
outputString = outputString.Replace(accentMapping(i), accentMapping(i+1))
Next
Return outputString
End Function
It does not works, bur for other reasons…
Of course, I supposed that
Could my existing project handle RegEx different from a new project?
Thanks for the effort, the result is what I need, but I have to make it work with a generic existing RegEx option in my app…
it was not my effort, but a chatGPT one …