Android Question Regex string contains some letter

WimS

Member
Licensed 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.
 

WimS

Member
Licensed User
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

WimS

Member
Licensed User
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

WimS

Member
Licensed User
This is working.

B4X:
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

Mahares

Expert
Licensed User
Longtime User
This is working.
Did you try this without having to replace the CRLF with space. It works:
B4X:
 Sub BevatAlphaNumeriek(Str As String) As Boolean   
    Dim pattern As String = ".*[adehj\n].*"
    Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str)   
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
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:
B4X:
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

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
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:
B4X:
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
B4X:
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

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top