B4J Question RegEx found in B4A, not fonund in B4J

Sergio Haurat

Active Member
Licensed User
Longtime User
What am I doing wrong?. Please note that it doesn't work in B4J or I can't find the right way to write the RegEx pattern

What I need:
B4A, regex works perfectly
This woks!:
Dim regexHostInfo As String = "PING ([^ ]+) \(([^)]+)\) "
Dim matchHost As Matcher = Regex.Matcher(regexHostInfo, "PING google.com (216.58.202.78) 56(84) bytes of data.")
If matchHost.Find Then
  'Hello match!
End If

B4J, regex not found
Not working:
Dim regexHostInfo As String = "Haciendo ping a ([^ ]+) [([^)]+)].*"
Dim matchHost As Matcher = Regex.Matcher(regexHostInfo, "Haciendo ping a www.google.com.ar [172.217.173.227] con 32 bytes de datos:")
If matchHost.Find Then
  'Hello match!
End If
 
Solution
B4J
B4X:
Dim regexHostInfo As String = "Haciendo ping a ([^ ]+) \[([^)]+)\].*"
you just needed to escape the brackets around the ip address.

Sergio Haurat

Active Member
Licensed User
Longtime User
Well, your code works in B4A and you are looking for a B4j solution, so b4j questions is the right place :)
Well, I learned it today and I will in the future.
1. Don't republish libraries associated with other posts (Erel told me this)
2. The post is from B4?, in the forum with the problem.

My apologies and thanks for your clarification.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
B4J
B4X:
Dim regexHostInfo As String = "Haciendo ping a ([^ ]+) \[([^)]+)\].*"
you just needed to escape the brackets around the ip address.
 
Upvote 0
Solution
Top