<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/20723" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2020-03-10T12:11:37-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/20723</id>

		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2020-03-10T12:11:37-04:00</updated>

		<published>2020-03-10T12:11:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=108062#p108062</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=108062#p108062"/>
		<title type="html"><![CDATA[Regexp match]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=108062#p108062"><![CDATA[
Great. Thanks!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Tue Mar 10, 2020 12:11 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[AlbozZz]]></name></author>
		<updated>2020-03-10T08:46:12-04:00</updated>

		<published>2020-03-10T08:46:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=108061#p108061</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=108061#p108061"/>
		<title type="html"><![CDATA[Hi]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=108061#p108061"><![CDATA[
The Tcl and PHP RE languages are quite similar in this area (there are areas where they diverge, but this RE doesn't use them). The behaviour of using a match array in PHP is much like using the -inline option to regexp and saving the result (a list) in a variable that can then be indexed into (e.g., with lindex). The wrapping %…%i part of the PHP code becomes the -nocase option. Finally, you'll want to put REs in Tcl in {braces}.<br><br><div class="codebox"><p>Code: </p><pre><code>set match [regexp -inline -nocase {(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&amp;]v=)|youtu\.be/)([^"&amp;?/ ]{11})} $url]set youtube_id [lindex $match 1]</code></pre></div>We can split that into more lines for readability.<br><div class="codebox"><p>Code: </p><pre><code>set RE {(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&amp;]v=)|youtu\.be/)([^"&amp;?/ ]{11})}set match [regexp -inline -nocase $RE $url]set youtube_id [lindex $match 1]</code></pre></div><br>The first line here is storing the regular expression in a variable, and the second line applies the RE to whatever is in the url variable, storing the resulting list in the match variable for later examination. Which is a good match for what preg_match was doing over in PHP.<br><br>Since you only actually want the ID, that's easy too:<br><div class="codebox"><p>Code: </p><pre><code>set RE {(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&amp;]v=)|youtu\.be/)([^"&amp;?/ ]{11})}regexp -nocase $RE $url --&gt; youtube_id</code></pre></div>If desired, you can embed the caselessness inside the RE, similar to the PHP case, by prepending <br><div class="codebox"><p>Code: </p><pre><code>(?i): set RE {(?i)(?:youtube ...)}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12845">AlbozZz</a> — Tue Mar 10, 2020 8:46 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2020-03-09T09:44:14-04:00</updated>

		<published>2020-03-09T09:44:14-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=108056#p108056</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=108056#p108056"/>
		<title type="html"><![CDATA[Regexp match]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=108056#p108056"><![CDATA[
Hi,<br><br>would appreciate if someone with far better knowledge of regexp could help me out turning this regexp from PHP into TCL:<div class="codebox"><p>Code: </p><pre><code>preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&amp;]v=)|youtu\.be/)([^"&amp;?/ ]{11})%i', $url, $match);</code></pre></div>Thanks.<br><br>PS: Taken from <a href="https://gist.github.com/ghalusa/6c7f3a00fd2383e5ef33" class="postlink">here</a> cos it matches multiple patterns.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Mar 09, 2020 9:44 am</p><hr />
]]></content>
	</entry>
	</feed>
