将此regexp从PHP转换为TCL:

将此regexp从PHP转换为TCL:,tcl,Tcl,如果对regexp有更好了解的人能够帮助我将此regexp从PHP转换为TCL,我将不胜感激: preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); 我从这里开始: <?php // Here is a sample of the URLs this regex mat

如果对regexp有更好了解的人能够帮助我将此regexp从PHP转换为TCL,我将不胜感激:

preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); 
我从这里开始:

<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)

// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
// http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/dQw4w9WgXcQ
// http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ
// http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ

// It also works on the youtube-nocookie.com URL with the same above options.
// It will also pull the ID from the URL in an embed code (both iframe and object tags)

preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
$youtube_id = $match[1];
?>

Tcl和PHP RE语言在这一方面非常相似——它们在某些方面存在分歧,但这两种RE并不使用它们。在PHP中使用匹配数组的行为非常类似于对regexp使用-inline选项,并将结果保存在一个变量列表中,然后可以将该变量编入索引,例如使用lindex。PHP代码的包装%…%i部分变成了-nocase选项。最后,您需要将REs放在{大括号}中的Tcl中

设置匹配项[regexp-inline-nocase{:youtube?:-nocookie?\.com/?:[^/]+/.+/.+/.+/|?:v | e?:mbed?/|。*[?&]v=| youtu\.be/[^&?/.{11}$url] 这一行仅用于堆栈溢出上的中断代码高亮显示 设置youtube_id[lindex$match 1] 为了便于阅读,我们可以把它分成多行

设置RE{:youtube?:-nocookie?\.com/?:[^/]+/.+/.+/.+/|?:v|e?:mbed?/|。*[?&]v=| youtu\.be/[^&?/]{11} 这一行仅用于堆栈溢出上的中断代码高亮显示 设置匹配[regexp-inline-nocase$RE$url] 设置youtube_id[lindex$match 1] 这里的第一行将正则表达式存储在一个变量中,第二行将RE应用于url变量中的任何内容,将结果列表存储在match变量中以供以后检查。这与preg_match在PHP中所做的非常匹配

因为您实际上只需要ID,这也很简单:

set RE {(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})}
#"# This line is just for the broken code highlighter here on Stack Overflow
regexp -nocase $RE $url --> youtube_id

->实际上是一个虚拟变量名,它被分配了整个匹配的URL,但使用箭头更容易记忆。

也许您可以向我们显示您的URL。。。您期望的结果是RE似乎是用于从YouTube URL提取项目标记。我从我刚才添加的最后代码php中获取它我希望tls为tcl提交regex而不是phpIf所需的结果,您可以通过预加?i:set RE{?i?:YouTube…}将无大小写嵌入RE中,类似于php大小写Thx很多人正是我在寻找的: