Android Question Regex string contains some letter

WimS

Member
Licensed User
Longtime User
I need a regex expression to detect if a string contains some letters.
The string can contain everything but I need to know if there are some alphabetic characters in.
 
See below :

Str = "AT+AB Bypass"

Public Sub BevatAlphaNumeriek(Str As String) As Boolean
Dim pattern As String = ".*[adehj].*"
Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str)
End Sub


I get false return
 
Upvote 0
Thanks Erel en Jorge.

I see whats the matter: when the string contains CRLF at the end, it return false otherwhise it return true
 
Upvote 0
This is working.

Code:
Public Sub BevatAlphaNumeriek(Str As String) As Boolean
    
    Str = Str.Replace(CRLF," ")
    Dim pattern As String = ".*[adehj].*"
    Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str)
    
End Sub
 
Upvote 0
The string contains the source of a async stream.
Your posts did not indicate that before, but I tested it with a string and it worked. That is why you have to explain yourself more clearly to avoid unnecessary posts from others.
I tried my code like this:
Code:
Log(BevatAlphaNumeriek("AT+AB" & CRLF & "Bypass" ))  'true
    Log(BevatAlphaNumeriek("AT+AB Bypass" & CRLF))       'true
    Log(BevatAlphaNumeriek("AT+AB Bypass"))                 'true
    Log(BevatAlphaNumeriek("Victory"))                     'false
 
Upvote 0
Upvote 0
Sub BevatAlphaNumeriek(Str As String) As Boolean
' Dim pattern As String = ".*[adehj\n].*"
Dim pattern As String = "(?s).*[adehj].*"
Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str)
End Sub
@Mahares: You're close but your solution would produce a true for
Hi Oliver: Your pattern produces the same results as the one I posted:
Code:
Sub BevatAlphaNumeriek(Str As String) As Boolean   
'    Dim pattern As String = ".*[adehj\n].*"
    Dim pattern As String = "(?s).*[adehj].*"    
    Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str)   
End Sub
Code:
Log(BevatAlphaNumeriek("AT+AB" & CRLF & "Bypass" ))  'true
    Log(BevatAlphaNumeriek("AT+AB Bypass" & CRLF))       'true
    Log(BevatAlphaNumeriek("AT+AB Bypass"))                 'true
    Log(BevatAlphaNumeriek("Victory"))                     'false
 
Upvote 0
Upvote 0
Back
Top