Darrin Smith wrote:Why does m.matches() return false?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Darrin Smith wrote:
Why does m.matches() return false?
Henry Wong wrote:
Darrin Smith wrote:
Why does m.matches() return false?
When I tested it, I got "true" from m.matches().
Henry
Darrin Smith wrote:
Every time I run the code it shows false. Driving me up a wall trying to figure it out. It SHOULD match.
Winston Gutkowski wrote:
Darrin Smith wrote:Why does m.matches() return false?
Well, I suspect you don't need the '|' because you don't appear to be matching on it, but I wouldn't have thought it would need escaping inside square brackets.
I also think that "(-?[0-9]+([.][0-9]+)?)" is more correct for a decimal number.
Winston
Darrin Smith wrote:I tried doing this too...no help:
...
Pattern.compile(".*=(-?[0-9]+\\.[0-9]+?),([0-9]+),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),([0-9]*),([0-9]*),([0-9]*)");
...
Again though, using a tool it works. Just not when I run it in a Java application.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Darrin Smith wrote:I tried doing this too...no help:
...
Pattern.compile(".*=(-?[0-9]+\\.[0-9]+?),([0-9]+),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),([0-9]*),([0-9]*),([0-9]*)");
...
Again though, using a tool it works. Just not when I run it in a Java application.
That's not quite what I was thinking of. I tried this:
Pattern.compile("GN=-?[0-9]+([.][0-9]+)?(,-?[0-9]+([.][0-9]+)?){7}");
against your test string and it worked just fine.
I suspect you should also make your initial ".*" string ".*?" or "[^=]*".
Winston
Just FYI, my code:
and the output:
Darrin Smith wrote:I tried that and it did work on the string I sent but failed on others (sometimes no decimal was sent, etc.).
I modified it slightly and ended up with this which works great!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |