Android Question Regex Replace with Unicode Support ?

epiCode

Active Member
Licensed User
I use this pattern to detect all matching numbers irrespective of unicode script which is \p{N}.
It works fine on all regex testing sites but it returns a blank string when used with regex.replace.

B4X:
Sub RemoveNumbersAndBrackets(inputString As String) As String
    Dim outputString As String
    Dim lines() As String
    lines = Regex.Split("\n", inputString) ' Split inputString into an array of lines using regex
    
    For Each line As String In lines
        line = Regex.Replace("[\p{N}()\\\[\]]+", "", line) ' Remove numbers and brackets from the line
        line = Regex.Replace("^[\.]+", "", line) ' Remove full stop from beginning of line (left when numbers are removed)
        line = line.Trim 
        If line <> "" Then ' Check if the line is not blank
            outputString = outputString & line & CRLF ' Append modified line to outputString
        End If
    Next
    Return outputString.Trim
End Sub


Some test string:

B4X:
1. (123) Hello world!\n2. This is a test.\n3 456789. \n\n
2. (३५४) line two
3. (٣١٢٤) Hello world!\n2. This is line three.\n3. 456789\n\n
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…