From 0b57ee6af06b5fb3fa75b5578d4f2696591fb84c Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 13 Jun 2020 15:23:14 -0700 Subject: [PATCH] better gps regex --- Location.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Location.cpp b/Location.cpp index 395ae27..335785e 100644 --- a/Location.cpp +++ b/Location.cpp @@ -26,8 +26,8 @@ CLocation::CLocation() { - crc = std::regex("^.*([0-9]{1,2})([0-9]{2}\\.[0-9]{1,})([NS])/([0-9]{1,3})([0-9]{2}\\.[0-9]{1,})([WE]).*$", std::regex::extended); - rmc = std::regex("^.*,([0-9]{1,2})([0-9]{2}\\.[0-9]{1,}),([NS]),([0-9]{1,3})([0-9]{2}\\.[0-9]{1,}),([WE]),.*$", std::regex::extended); + crc = std::regex("[^0-9]([0-9]{1,2})([0-9]{2}\\.[0-9]{1,})([NS])/([0-9]{1,3})([0-9]{2}\\.[0-9]{1,})([WE])", std::regex::extended); + rmc = std::regex("[^0-9]([0-9]{1,2})([0-9]{2}\\.[0-9]{1,}),([NS]),([0-9]{1,3})([0-9]{2}\\.[0-9]{1,}),([WE]),", std::regex::extended); } // returns true on success @@ -38,9 +38,9 @@ bool CLocation::Parse(const char *instr) trim(s); if (0 == s.find("$$CRC")) { - std::regex_match(s.c_str(), cm, crc, std::regex_constants::match_default); + std::regex_search(s.c_str(), cm, crc, std::regex_constants::match_default); } else if ((0 == s.find("$GPGGA")) || (0 == s.find("$GPRMC"))) { - std::regex_match(s.c_str(), cm, rmc, std::regex_constants::match_default); + std::regex_search(s.c_str(), cm, rmc, std::regex_constants::match_default); } else { if ('$' == s.at(0)) std::cerr << "can't parse GPS string: " << s << std::endl;