Hello. Can I check if a variable contains some string ?? suppose Set(var=foobar) can I check if ${var} contains "foo" ?? Like the php-function strstr. Jonas. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20100617/758fee7e/attachment.htm
On Thu, Jun 17, 2010 at 03:37:15PM +0200, Jonas Kellens wrote:> Hello. > > Can I check if a variable contains some string ?? > > suppose Set(var=foobar) > > can I check if ${var} contains "foo" ??core show function REGEX. Should work well as long as the string to match has no special characters of its own. -- Tzafrir Cohen icq#16849755 jabber:tzafrir.cohen at xorcom.com +972-50-7952406 mailto:tzafrir.cohen at xorcom.com http://www.xorcom.com iax:guest at local.xorcom.com/tzafrir
This worked in 1.4.30 ; regex test exten => 1234,1,Answer exten => 1234,n,Set(footest=foobar) exten => 1234,n,verbose(test value ${footest}) exten => 1234,n,Set(test=${REGEX("[foo]" ${footest})}) exten => 1234,n,verbose(test returned ${test}) exten => 1234,n,Playback(vm-goodbye) exten => 1234,n,hangup This line did not exten => 1234,n,Set(test=${REGEX("/foo/" ${footest})}) -----Original Message----- From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Tzafrir Cohen Sent: Thursday, June 17, 2010 9:05 AM To: asterisk-users at lists.digium.com Subject: Re: [asterisk-users] Check if variable contains strings On Thu, Jun 17, 2010 at 03:37:15PM +0200, Jonas Kellens wrote:> Hello. > > Can I check if a variable contains some string ?? > > suppose Set(var=foobar) > > can I check if ${var} contains "foo" ??core show function REGEX. Should work well as long as the string to match has no special characters of its own. -- Tzafrir Cohen icq#16849755 jabber:tzafrir.cohen at xorcom.com +972-50-7952406 mailto:tzafrir.cohen at xorcom.com http://www.xorcom.com iax:guest at local.xorcom.com/tzafrir -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
This also gives result "1" but is not correct : exten => 1234,n,Set(test2=${REGEX("[fot]" ${footest})}) exten => 1234,n,verbose(test2 returned ${test2}) [Jun 17 16:59:01] -- Executing [1234 at from:7] Verbose("SIP/13-00000096", "test2 returned 1") in new stack [Jun 17 16:59:01] test2 returned 1 Jonas On 06/17/2010 04:22 PM, Danny Nicholas wrote:> This worked in 1.4.30 > ; regex test > exten => 1234,1,Answer > exten => 1234,n,Set(footest=foobar) > exten => 1234,n,verbose(test value ${footest}) > exten => 1234,n,Set(test=${REGEX("[foo]" ${footest})}) > exten => 1234,n,verbose(test returned ${test}) > exten => 1234,n,Playback(vm-goodbye) > exten => 1234,n,hangup > > This line did not > exten => 1234,n,Set(test=${REGEX("/foo/" ${footest})})-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20100617/8908bf58/attachment.htm
On Thursday 17 June 2010 10:01:40 Jonas Kellens wrote:> This also gives result "1" but is not correct : > > exten => 1234,n,Set(test2=${REGEX("[fot]" ${footest})}) > exten => 1234,n,verbose(test2 returned ${test2}) > > [Jun 17 16:59:01] -- Executing [1234 at from:7] > Verbose("SIP/13-00000096", "test2 returned 1") in new stack > [Jun 17 16:59:01] test2 returned 1Actually, it is correct. Your regex specifies a match for any string that contains "f" or "o" or "t", because the square brackets create a character class. If you remove the square brackets, it will do what you expect. -- Tilghman Lesher Digium, Inc. | Senior Software Developer twitter: Corydon76 | IRC: Corydon76-dig (Freenode) Check us out at: www.digium.com & www.asterisk.org