am new to regex, so am having a hard time compiling my own pattern.
Basically am reading the LogCat from my android phone and am trying to break this string into pieces to be able to display it in TextView
This is the actually string am trying to token.
“07-06 12:18:45.790: W/dalvikvm(571): TaintLog: OSNetworkSystem.write(91.121.171.39) received data with tag 0x400 data=[POST / HTTP/1.1”
Am able to retrieve the number after “Tag” using the scanner method, but now I need to extract the IP address from the OSnetworkSystem.Write(xxx.xxx.xxx.xxx)
Can anybody provided me some tips on what to use to be able to extra the IP address.
Well, for the regex part, I can help on.
The regular expression:
Would match any IP Address in a given string.
For RegExp I use a website, http://rubular.com/ which has really helped with my workflow. I can throw in any number of “test cases” and start writing the regex code.
Editing per comments below.
Instead of re-inventing the wheel. I found a great write up on IPv4 Regex:
How do I write a regular expression that matches an IPv4 dotted address?
Which basically says:
It is long and complex. But following the write up, should give you some good understanding in what it actually does.
In my experience, the more complex & relient we get with regex success rates, the more it is going to probably fail. I’d suggest never relying on regex for critical data … Find another way, there always is 🙂