Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global flag #5

Open
SamuelePilleri opened this issue May 12, 2016 · 8 comments
Open

Global flag #5

SamuelePilleri opened this issue May 12, 2016 · 8 comments
Assignees

Comments

@SamuelePilleri
Copy link

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?

@tunnckoCore
Copy link
Member

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?

@SamuelePilleri
Copy link
Author

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
Copy link
Author

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

@tunnckoCore
Copy link
Member

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

@SamuelePilleri
Copy link
Author

SamuelePilleri commented May 12, 2016 via email

@tunnckoCore
Copy link
Member

tunnckoCore commented May 12, 2016

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.

@SamuelePilleri
Copy link
Author

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?

@tunnckoCore tunnckoCore self-assigned this May 13, 2016
@tunnckoCore
Copy link
Member

tunnckoCore commented Jul 14, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants