2

Following this tutorial by Ray Camden...

Trying to fetch the ID from the YouTube URL:

<cfset regex = "^(?:[^?]+\?v=|[^v]+/v/)([^&##/]+).*|http://youtu.be/">;

<cfset videoid = rereplace(u, regex, "\1" ) /> 

But the youtu.be does not seems to work here; other YouTube URLs seems fine.

Fish Below the Ice
  • 1,273
  • 13
  • 23
  • 1
    ray mentioned at the end of the post how to handle `youtu.be`, simply detect whether the url contains `youtu.be`, and if it does, use `listlast`. Not quite sure if it's worth it to complicate the regexp to have it handle both – Kevin B Apr 29 '14 at 19:55
  • code worked fine, so some other typo error was there. Thanks –  Apr 29 '14 at 20:33

1 Answers1

1

How about

<cfset regex = "#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#">;
<cfset videoid = rereplace(u, regex, "\1" ) /> 

Source PHP Regex to get youtube video ID?

Community
  • 1
  • 1
udnisap
  • 899
  • 1
  • 10
  • 19
  • getting an error using this: ` Invalid CFML construct found on line 9 at column 21. ColdFusion was looking at the following text: ? The CFML compiler was processing: An expression beginning with (, on line 9, column 20.This message is usually caused by a problem in the expressions structure. An expression beginning with /", on line 9, column 18.This message is usually caused by a problem in the expressions structure. A cfset tag beginning on line 9, column 4.` –  Apr 29 '14 at 19:57
  • i think the start of coldfusion based regex is like that you written above, –  Apr 29 '14 at 19:57
  • I dont have CodeFusion to check but with a minor change like escaping a forward slash would do the trick. Try `#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be\/)[^&\n]+#` – udnisap Apr 29 '14 at 20:00
  • pound is coldfusion reserved(#), so not sure it will work, but trying –  Apr 29 '14 at 20:05
  • still getting same issue –  Apr 29 '14 at 20:06