I have the following code that will extract an email address from a text string, which will get replaced by text inside a database field.
The string will contain a single email address. I have already split the email address as follows:
- test@test.co.za - Full email address
- test - email user
- test.co.za - Domain
I have included code that can replace all characters as *************** (Full Email) or the individual parts.
It would be easy to combine the text again when I have done what I needed.
The result I am trying to get:
te**@********za
Was thinking about hiding everything in the first part, except first 2 characters and in the last part, everything except last 2 characters.
Dim newText As string = ""
Dim senText As String = "This is a long string that we will try test@test.co.za to extract the email address from, it might exist anywhere in this string."
Dim emailRegEx As New Regex("(\S+)@([^\.\s]+)(?:\.([^\.\s]+))+")
Dim m As Match = emailRegEx.Match(senText)
If m.Success Then
newText = m.ToString
End If
Dim mystr As String = newText
Dim cut_at As String = "@"
Dim x As Integer = InStr(mystr, cut_at)
Dim string_before As String = mystr.Substring(0, x - 1)
Dim string_after As String = mystr.Substring(x + cut_at.Length - 1)
Dim myString As String = New String("*"c, newText.Length)
Dim PrivateMail As String = ""
response.write(newText)
response.write(myString)
response.write(string_before)
response.write(string_after)
Any help would be greatly appreciated.