<?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/15226" />

	<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>2008-01-07T12:27:10-04:00</updated>

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

		<entry>
		<author><name><![CDATA[CrazyCat]]></name></author>
		<updated>2008-01-07T12:27:10-04:00</updated>

		<published>2008-01-07T12:27:10-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=79861#p79861</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=79861#p79861"/>
		<title type="html"><![CDATA[Using a proc in a regsub?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=79861#p79861"><![CDATA[
OK, that's what I was thinking...<br>I'm used to use regexp in PHP, with callback function and eval...<br><br>Thanks a lot<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=691">CrazyCat</a> — Mon Jan 07, 2008 12:27 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2008-01-07T08:32:18-04:00</updated>

		<published>2008-01-07T08:32:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=79858#p79858</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=79858#p79858"/>
		<title type="html"><![CDATA[Re: Using a proc in a regsub?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=79858#p79858"><![CDATA[
I think you mean "\\?", not "\?". The first backslash is substituted when the regsub line is evaluated, resulting in "?" being passed as a pattern to regsub, which will interpret the unescaped "?" as a quantifier - leading to the error message you got.<br><br>There is no way to invoke a command for each match using regsub - currently - some people in #tcl@freenode are experimenting with a new regexp engine that may be included in a future version of Tcl, but don't hold your breath <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><br><br>However... replacing a single character is easy to do using split,foreach and append:<div class="codebox"><p>Code: </p><pre><code>proc replacething {str find code} {set out ""foreach chr [split $str ""] {append out [if {[string eq $chr $find]} {eval $code} {set chr}]}set out}# tclsh tests:% proc rand i {expr {int(rand()*$i)}};# there's no [rand] in tclsh% replacething "Hello????" ? {rand 9}Hello5643% replacething "axaxax" x {format %c [expr {65+int(rand()*26)}]}aZaWaU</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Mon Jan 07, 2008 8:32 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[CrazyCat]]></name></author>
		<updated>2008-01-07T07:14:18-04:00</updated>

		<published>2008-01-07T07:14:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=79857#p79857</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=79857#p79857"/>
		<title type="html"><![CDATA[Using a proc in a regsub?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=79857#p79857"><![CDATA[
Hello there,<br><br>I'm trying to do a small tcl who generate a random string based on a pattern, I want to replace a special char ("?") with a random other char. The trouble is that this special char could be several times in the pattern, I don't want to have the same replacement.<br><br>I'm trying with someting like:<div class="codebox"><p>Code: </p><pre><code>proc rnd:replace {pattern} {   regsub -all -- \? $pattern [rand 9] pattern   return pattern}</code></pre></div>And sure, it fails (couldn't compile regular expression pattern: quantifier operand invalid)...<br>Is there a way to eval a proc in a regsub?<br><br>Thanks by advance<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=691">CrazyCat</a> — Mon Jan 07, 2008 7:14 am</p><hr />
]]></content>
	</entry>
	</feed>
