But I've just noticed, it'll only match the first occurrence... the second array entry is the stuff in parenthesis. As far as I'm aware the /g modifier should make it global, but it's not in this case.

justspree
—
2011-06-25T14:49:53Z —
#10

Hi micky, I think I can make do with the "without the extension" issue because it seems like even when i tried on facebook, it is the same result. For now the only check I need to add in is for the below result as well.

The first array element is the whole match, which is 'www.youtube/watc', the second array element is the first matched parethesis which is 'watc'.

Now for some reason, it's including the '/' as being matched by [-a-zA-Z0-9_], which as far as I'm aware it shouldn't do. Then, it's matching 'watc' as the last 4 characters after the first backslash with '([a-zA-Z\.]{2,4})'. Which is also confusing, since there's no backslash featured in the preceding part of the RegExp.

Now in PHP (and most probably Perl), I think preg_match behaves a little differently. So I'm afraid I'm gonna have to duck out here, cos I'm at a loss as to why this isn't working. Hopefully someone who knows a little more about javascript RegExp will be able to pick up the threat from here.

justspree
—
2011-06-25T16:39:56Z —
#15

Yes micky, this is just weird, but thanks for your great help anyway. If anyone have any advice would greatly appreciate.

Meanwhile I'll just keep trying...

mickyginger
—
2011-06-26T17:22:22Z —
#16

Hey there,

So a friend of mine, who is much more intelligent than I has pointed out that javascript behaves differently depending on the way you use a regex. So if you use this method:

will operate 'properly'. In that case the regex I gave you works correctly, and will return an array of matches. Note how the regex is no longer in inverted commas, and the modifiers are after the last backslash. The backslash operates at the delimiter of the regex, so you need to escape all the other backslashes throughout the regex.