1

I am trying to check if a string is a valid deep link from Waze Live Map. A Waze Live Map deep link looks something like this:

https://www.waze.com/ul?place=ChIJj61dQgK6j4AR4GeTYWZsKWw&ll=37.42199990%2C-122.08405750&navigate=yes

Given a string, I want to know if it is a valid Waze live map link. Most important, I want to know if it has the longitude and latitude at least.

I have tried the following:

String str = 'https://www.waze.com/ul?place=ChIJj61dQgK6j4AR4GeTYWZsKWw&ll=37.42199990%2C-122.08405750&navigate=yes'; 
var wazeUrlPattern = r"https:\/\/www.waze.com\/ul\?ll\=(.)*([1-9]+\.[1-9]+)%2C([1-9]+\.[1-9]+)(.)?";
bool valid = new RegExp(wazeUrlPattern, caseSensitive:false).hasMatch(str);
if(!valid) {
    print("The url is not valid waze live map link!");
    return;
  }
// Do something with the longitude and latitude and maybe other parameters

This is not working for me and I would like some help in figuring out the problem.

atefsawaed
  • 543
  • 8
  • 14
  • I would try to help but I don't know the format of what deep waze is. Maybe you could list some specific allowed characters and all that. Or, you seem to know regular expressions, what specific regex problem are you having trouble with ? –  Aug 01 '20 at 20:37
  • Also, I don't advise creating a regex object and calling it on the stack. –  Aug 01 '20 at 20:39
  • Note that Waze Deep Links that always have the `ll` parameter, according to https://developers.google.com/waze/deeplinks (they might have for example a link to navigate the favorite and others) – Mattia Aug 01 '20 at 21:00

5 Answers5

2

Consider not using a RegExp. If you first parse the input as a URI, you get normalization an can still query the individual parts:

bool isWazeDeepLink(String url) {
  var parsedUrl = Uri.parse(url);
  if (parsedUrl.isScheme("http") && 
      parsedUrl.host == "www.waze.com" &&
      parsedUrl.path == "/ul" &&
      parsedUrl.queryParameters["ll"] != null) {
    // Or check format of the `ll` parameter
    return true;
  }
  return false;
}

You can also use a RegExp, but you should consider that the scheme and host fields are case insensitive, and so is the %2c escape, but the path isn't, so you'd want something like:

 var re = RegExp(r"^[hH][tT][tT][pP]://[wW]{3}\.[wW][aA][zZ][eE]\.[cC][oO][mM]"
         r"/ul\?.*(?<=[?&])ll=(?:-?\d+(?:\.\d+))%2[C](?:-?\d+(?:\.\d+))(?:[&#]|$)");

This will match http://www.waze.com/ in any case, then ul as lower case, and then any following string containing a complete URL parameter (prefixed by ? og &, followed by &, # or the end), which has the format ll= followed by a number, %2c or %2C and another number.

(Or you can start by parsing the input as a URI, then doing a toString to get a normalized URI, then the other regexps suggested here will work as well).

lrn
  • 64,680
  • 7
  • 105
  • 121
1

You could use this:

var wazeUrlPattern = r"https://www\.waze\.com/ul\?.*ll=[\d.-]+%2C[\d.-]+";

Demo

jdaz
  • 5,964
  • 2
  • 22
  • 34
1

Use

https://www\.waze\.com/ul\?.*?&ll=(-?\d+\.\d+)%2C(-?\d+\.\d+)

See proof

Escape dots to match literal dots and you have ?ll while there is ?place and &ll= later in the URL. Also, longitude and latitude may have optional - in front.

EXPLANATION

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  https://www              'https://www'
--------------------------------------------------------------------------------
  \.                       '.'
--------------------------------------------------------------------------------
  waze                     'waze'
--------------------------------------------------------------------------------
  \.                       '.'
--------------------------------------------------------------------------------
  com/ul                   'com/ul'
--------------------------------------------------------------------------------
  \?                       '?'
--------------------------------------------------------------------------------
  .*?                      any character except \n (0 or more times
                           (matching the least amount possible))
--------------------------------------------------------------------------------
  &ll=                     '&ll='
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    -?                       '-' (optional (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  %2C                      '%2C'
--------------------------------------------------------------------------------
  (                        group and capture to \2:
--------------------------------------------------------------------------------
    -?                       '-' (optional (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \2
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37
1

You may use following regex:

https:\/\/www\.waze\.com\/ul\?.*?ll\=(\d+\.\d+)%2C-(\d+\.\d+)

Regex Demo

Details

https:\/\/www\.waze\.com\/ul\?.*?\&: matches url til ll argument

(\d+\.\d+): combination of digits and one dot character

%2C-: characters between coordination

mjrezaee
  • 1,100
  • 5
  • 9
1

Try this regular expression:

https:\/\/www\.waze\.com\/ul\?place=([^&]*)&ll=-?([1-9]\d*\.\d+)%2C-?([1-9]\d*\.\d+).*

For convenience you will have place on $1 (Group 1) and the remaining groups will provide the longitude and latitude.

Please check the demo here.

marianc
  • 439
  • 1
  • 4
  • 13