youtube-regex icon indicating copy to clipboard operation
youtube-regex copied to clipboard

Global flag

Open SamuelePilleri opened this issue 9 years ago • 8 comments

I tried, just for curiosity, against this URL https://www.youtube.com/watch?v=_T2Dxgn-lls in a normal Firefox browser with normal .match and it wouldn't work unless removing the g flag. After removing it the regex returned the id in the array as needed. Is this the wanted behaviour?

SamuelePilleri avatar May 12 '16 19:05 SamuelePilleri

Hi, it's just a function that returns a regex, nothing more, so..

But yea, you have right and it may be good to have options as the other packages in that org have. i'll try to do that tonight.

it wouldn't work

what you mean with that?

tunnckoCore avatar May 12 '16 20:05 tunnckoCore

I just meant it doesn't work without removing the flag, sorry. Again, this was just my usecase, it might not apply well in other contexts.

SamuelePilleri avatar May 12 '16 20:05 SamuelePilleri

Mainly, my question - in other words - was why is there a "nested" capture for the ID if just the first match is returned.

SamuelePilleri avatar May 12 '16 20:05 SamuelePilleri

Can you try it on chrome? Or what version of FF you use? I'm noticing now few "firefox specific notes" in mozilla docs https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/match

tunnckoCore avatar May 12 '16 20:05 tunnckoCore

I've tried with the latest version of Firefox under Windows 10 64 bits, I can tell you more tomorrow; I didn't know Firefox was "special".�

SamuelePilleri avatar May 12 '16 21:05 SamuelePilleri

I didn't know Firefox was "special".

Haha, same here. In anyway, i'm not using it from v3, lol.. Yea.. that's was years ago, and it was good.. mm yea.

tunnckoCore avatar May 12 '16 21:05 tunnckoCore

So, I run some tests, here the results.

With global flag: "https://www.youtube.com/watch?v=_T2Dxgn-lls".match(/(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/g)

  • Firefox 46.0.1, Windows 10 64 bit; Firefox 46.0, Ubuntu 16.04 64-bit Array [ "youtube.com/watch?v=_T2Dxgn-lls" ]
  • Microsoft Edge [object Array]["youtube.com/watch?v=_T2Dxgn-lls"]
  • Chromium 49.0.2623.108, Ubuntu 16.04 64-bit ["youtube.com/watch?v=_T2Dxgn-lls"]
  • Node.js v6.1.0, Ubuntu 16.04 64-bit [ 'youtube.com/watch?v=_T2Dxgn-lls' ]

Without global flag: "https://www.youtube.com/watch?v=_T2Dxgn-lls".match(/(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/)

  • Firefox 46.0.1, Windows 10 64 bit; Firefox 46.0, Ubuntu 16.04 64-bit Array [ "youtube.com/watch?v=_T2Dxgn-lls", "_T2Dxgn-lls" ]
  • Microsoft Edge [object Array]["youtube.com/watch?v=_T2Dxgn-lls", "_T2Dxgn-lls"]
  • Chromium 49.0.2623.108, Ubuntu 16.04 64-bit ["youtube.com/watch?v=_T2Dxgn-lls", "_T2Dxgn-lls"]
  • Node.js v6.1.0, Ubuntu 16.04 64-bit [ 'youtube.com/watch?v=_T2Dxgn-lls', '_T2Dxgn-lls' ]

Do really Chrome and Chromium behave differently?

SamuelePilleri avatar May 13 '16 17:05 SamuelePilleri

Hm, interesting, so probably we should rethink it. PRs welcome, since it works in node.

tunnckoCore avatar Jul 14 '17 16:07 tunnckoCore