Skip to content Skip to sidebar Skip to footer

Does This Regexp From Google Analytics Actually Do Anything?

Here's the section of code: var [...snip...] ye=/^(?:(?:https?|mailto|ftp):|[^:/?#]*(?:[/?#]|$))/i, This regular expression is used twice, both times with ye.test(a). And yet, I'

Solution 1:

(?:https?|mailto|ftp) matches http or https or mailto or ftp followed by :|[^:/?#]*, which is alternative: : or anything but :/>#, zero or more times, and then followed by (?:[/?#]|$), which means one of /?# or end of the string ($).

It will match mailto:, ftp:, https:, ftpasda (any string starting with ftp, https, http, mailto followed by a colon or any number of anything but :/>#).

UPDATE

After checking, it occurs that that alternation outside the non-capturing group applies not only to a colon, but also to whole group as well. So, if mailto or any string in the alternation doesn't match, regex engine will try matching pattern on the other side of mentioned alternation. This is example of string that won't match: :///////. Demo.

Post a Comment for "Does This Regexp From Google Analytics Actually Do Anything?"