W WimS Member Licensed User Longtime User Mar 16, 2020 #1 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Mar 16, 2020 #2 Code: If Regex.IsMatch2(".*[adehj].*", Regex.CASE_INSENSITIVE, "text here") Then Log("yes") End If Upvote 0
W WimS Member Licensed User Longtime User Mar 16, 2020 #3 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
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
Jorge M A Well-Known Member Licensed User Longtime User Mar 16, 2020 #4 Double check your code. The code proposed is working fine in B4X. Also you can check online : https://regex101.com/r/yQa9mD/1 Upvote 0
Double check your code. The code proposed is working fine in B4X. Also you can check online : https://regex101.com/r/yQa9mD/1
Erel B4X founder Staff member Licensed User Longtime User Mar 17, 2020 #5 Please use [code]code here...[/code] tags when posting code. Upvote 0
W WimS Member Licensed User Longtime User Mar 17, 2020 #6 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
Thanks Erel en Jorge. I see whats the matter: when the string contains CRLF at the end, it return false otherwhise it return true
W WimS Member Licensed User Longtime User Mar 17, 2020 #7 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
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
M Mahares Expert Licensed User Longtime User Mar 17, 2020 #8 WN van Surksum said: This is working. Click to expand... Did you try this without having to replace the CRLF with space. It works: Code: 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
WN van Surksum said: This is working. Click to expand... Did you try this without having to replace the CRLF with space. It works: Code: Sub BevatAlphaNumeriek(Str As String) As Boolean Dim pattern As String = ".*[adehj\n].*" Return Regex.IsMatch2(pattern,Regex.CASE_INSENSITIVE,Str) End Sub
W WimS Member Licensed User Longtime User Mar 17, 2020 #9 I try but it doesn't work. The string contains the source of a async stream. Upvote 0
M Mahares Expert Licensed User Longtime User Mar 17, 2020 #10 WN van Surksum said: The string contains the source of a async stream. Click to expand... 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
WN van Surksum said: The string contains the source of a async stream. Click to expand... 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
OliverA Expert Licensed User Longtime User Mar 17, 2020 #11 The pattern needs to be Code: Dim pattern As String = "(?s).*[adehj].*" it forces the dot character (.) to match new lines. See https://www.regular-expressions.info/modifiers.html @Mahares: You're close but your solution would produce a true for Code: "xxxx" & CRLF & "xxxx" Upvote 0
The pattern needs to be Code: Dim pattern As String = "(?s).*[adehj].*" it forces the dot character (.) to match new lines. See https://www.regular-expressions.info/modifiers.html @Mahares: You're close but your solution would produce a true for Code: "xxxx" & CRLF & "xxxx"
W WimS Member Licensed User Longtime User Mar 17, 2020 #12 Thats is what works in this way. Thanks to Mahares and OliverA. Upvote 0
M Mahares Expert Licensed User Longtime User Mar 17, 2020 #13 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 OliverA said: @Mahares: You're close but your solution would produce a true for Click to expand... 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
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 OliverA said: @Mahares: You're close but your solution would produce a true for Click to expand... 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
OliverA Expert Licensed User Longtime User Mar 17, 2020 #14 Mahares said: Hi Oliver: Your pattern produces the same results as the one I posted: Click to expand... did you try Code: "xxxx" & CRLF & "xxxx" ? Upvote 0
Mahares said: Hi Oliver: Your pattern produces the same results as the one I posted: Click to expand... did you try Code: "xxxx" & CRLF & "xxxx" ?