wildcard in replace function?
Posted in 2010
The poster asked whether Informix's REPLACE() function supports wildcards (e.g. replace(value,'*@','') to strip everything up to and including an '@'); neither '*' nor '%' worked. Replies confirmed REPLACE takes only literal strings: Fernando Nunes posted a simple SPL procedure that loops with SUBSTR to find the character and truncate the string, and Paul Watson suggested the free Regular Expression DataBlade as a better option, which another user endorsed as working well in production.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
Is it possible to use a wildcard in the replace function? I was trying something like this: replace(value, "*@", "") which would replace everything up to and including the @ with nothing. But no dice. I also tried % but that didn't fly either. Thoughts? Jonathon Wyza CX & CBORD System Administrator CX Programmer/Analyst Administrative Computing Bethel College (574)-257-3381 AIM: Iamwyza jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu> ============================== SLES 11x64 & IDS 11.50.FC6 "Don't document the problem, fix it." - Atli Björgvin Oddsson
On Thu, Sep 9, 2010 at 6:28 PM, Wyza, Jonathon <wyzaj@bethelcollege.edu>wrote:
> Is it possible to use a wildcard in the replace function?
>
> I was trying something like this:
>
> replace(value, "*@", "")
>
> which would replace everything up to and including the @ with nothing. But
> no
> dice. I also tried % but that didn't fly either. Thoughts?
>
>
The following seems to work, but it's not very elegant... I have the feeling
I've seen better, but that's what I could come up for now... Maybe others
can embarrass me :):
--------------------------------------------------------------------------------
----------------------------------------
cheetah@pacman.onlinedomus.net:fnunes-> dbaccess stores <<EOF
> CREATE PROCEDURE trunc_left( str VARCHAR(255), c CHAR) RETURNINGVARCHAR(255);
>
> DEFINE i SMALLINT;
>
> FOR i = 1 TO LENGTH(str)
>
> IF substr(str,i,1) = c
> THEN
> LET str = substr(str,i,LENGTH(str) - i + 1 );
> RETURN str;
> END IF;
> END FOR;
> END PROCEDURE;
>
> EXECUTE PROCEDURE trunc_left('Blah blah@and more blah blah!','@');> EOF
Database selected.
Routine created.
(expression) @and more blah blah!
1 row(s) retrieved.
Database closed.
--------------------------------------------------------------------------------
----------------------------------------
Regards.
> Jonathon Wyza
> CX & CBORD System Administrator
> CX Programmer/Analyst
> Administrative Computing
> Bethel College
> (574)-257-3381
> AIM: Iamwyza
> jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu>
> ==============================
> SLES 11x64 & IDS 11.50.FC6
>
> "Don't document the problem, fix it."
> - Atli Björgvin Oddsson
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
--0016364ef503183668048fda74c5
Have you looked the Regular Expression data blade ?
Paul Watson
Oninit LLC
Tel: +1 913 674 0360
Cell: +1 913 387 7529
Failure is not as frightening as regret
On 9 Sep 2010, at 16:38, "Fernando Nunes" <domusonline@gmail.com> wrote:
> On Thu, Sep 9, 2010 at 6:28 PM, Wyza, Jonathon
<wyzaj@bethelcollege.edu>wrote:
>
>> Is it possible to use a wildcard in the replace function?
>>
>> I was trying something like this:
>>
>> replace(value, "*@", "")
>>
>> which would replace everything up to and including the @ with nothing. But
>> no
>> dice. I also tried % but that didn't fly either. Thoughts?
>>
>>
> The following seems to work, but it's not very elegant... I have the feeling
> I've seen better, but that's what I could come up for now... Maybe others
> can embarrass me :):
>
>
>
--------------------------------------------------------------------------------
----------------------------------------
> cheetah@pacman.onlinedomus.net:fnunes-> dbaccess stores <<EOF
>> CREATE PROCEDURE trunc_left( str VARCHAR(255), c CHAR) RETURNING> VARCHAR(255);
>>
>> DEFINE i SMALLINT;
>>
>> FOR i = 1 TO LENGTH(str)
>>
>> IF substr(str,i,1) = c
>> THEN
>> LET str = substr(str,i,LENGTH(str) - i + 1 );
>> RETURN str;
>> END IF;
>> END FOR;
>> END PROCEDURE;
>>
>> EXECUTE PROCEDURE trunc_left('Blah blah@and more blah blah!','@');>> EOF
>
> Database selected.
>
> Routine created.
>
> (expression) @and more blah blah!
>
> 1 row(s) retrieved.
>
> Database closed.
>
>
>
--------------------------------------------------------------------------------
----------------------------------------
> Regards.
>
>> Jonathon Wyza
>> CX & CBORD System Administrator
>> CX Programmer/Analyst
>> Administrative Computing
>> Bethel College
>> (574)-257-3381
>> AIM: Iamwyza
>> jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu>
>> ==============================
>> SLES 11x64 & IDS 11.50.FC6
>>
>> "Don't document the problem, fix it."
>> - Atli Björgvin Oddsson
>>
>>
>>
>>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>
>>
>
> --
> Fernando Nunes
> Portugal
>
> http://informix-technology.blogspot.com
> My email works... but I don't check it frequently...
>
> --0016364ef503183668048fda74c5
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
I've never used any data blades, I don't even know if we are licensed for them.
Jonathon Wyza
CX & CBORD System Administrator
CX Programmer/Analyst
Administrative Computing
Bethel College
(574)-257-3381
AIM: Iamwyza
jonathon.wyza@bethelcollege.edu
==============================
SLES 11x64 & IDS 11.50.FC6
Dont document the problem, fix it.
Atli Björgvin Oddsson
________________________________________
From: ids-bounces@iiug.org [ids-bounces@iiug.org] on behalf of Paul Watson
[paul@oninit.com]
Sent: Thursday, September 09, 2010 6:03 PM
To: ids@iiug.org
Subject: Re: wildcard in replace function? [21217]
Have you looked the Regular Expression data blade ?
Paul Watson
Oninit LLC
Tel: +1 913 674 0360
Cell: +1 913 387 7529
Failure is not as frightening as regret
On 9 Sep 2010, at 16:38, "Fernando Nunes" <domusonline@gmail.com> wrote:
> On Thu, Sep 9, 2010 at 6:28 PM, Wyza, Jonathon
<wyzaj@bethelcollege.edu>wrote:
>
>> Is it possible to use a wildcard in the replace function?
>>
>> I was trying something like this:
>>
>> replace(value, "*@", "")
>>
>> which would replace everything up to and including the @ with nothing. But
>> no
>> dice. I also tried % but that didn't fly either. Thoughts?
>>
>>
> The following seems to work, but it's not very elegant... I have the feeling
> I've seen better, but that's what I could come up for now... Maybe others
> can embarrass me :):
>
>
>
--------------------------------------------------------------------------------
----------------------------------------
> cheetah@pacman.onlinedomus.net:fnunes-> dbaccess stores <<EOF
>> CREATE PROCEDURE trunc_left( str VARCHAR(255), c CHAR) RETURNING> VARCHAR(255);
>>
>> DEFINE i SMALLINT;
>>
>> FOR i = 1 TO LENGTH(str)
>>
>> IF substr(str,i,1) = c
>> THEN
>> LET str = substr(str,i,LENGTH(str) - i + 1 );
>> RETURN str;
>> END IF;
>> END FOR;
>> END PROCEDURE;
>>
>> EXECUTE PROCEDURE trunc_left('Blah blah@and more blah blah!','@');>> EOF
>
> Database selected.
>
> Routine created.
>
> (expression) @and more blah blah!
>
> 1 row(s) retrieved.
>
> Database closed.
>
>
>
--------------------------------------------------------------------------------
----------------------------------------
> Regards.
>
>> Jonathon Wyza
>> CX & CBORD System Administrator
>> CX Programmer/Analyst
>> Administrative Computing
>> Bethel College
>> (574)-257-3381
>> AIM: Iamwyza
>> jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu>
>> ==============================
>> SLES 11x64 & IDS 11.50.FC6
>>
>> "Don't document the problem, fix it."
>> - Atli Björgvin Oddsson
>>
>>
>>
>>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>
>>
>
> --
> Fernando Nunes
> Portugal
>
> http://informix-technology.blogspot.com
> My email works... but I don't check it frequently...
>
> --0016364ef503183668048fda74c5
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
*******************************************************************************
Forum Note: Use "Reply" to post a response in the discussion forum.
Its free and one of the most useful you can install
Cheers
Paul
> I've never used any data blades, I don't even know if we are licensed for
> them.
>
> Jonathon Wyza
> CX & CBORD System Administrator
> CX Programmer/Analyst
> Administrative Computing
> Bethel College
> (574)-257-3381
> AIM: Iamwyza
> jonathon.wyza@bethelcollege.edu
> ==============================
> SLES 11x64 & IDS 11.50.FC6
>
> Dont document the problem, fix it.
> Atli Björgvin Oddsson
>
> ________________________________________
> From: ids-bounces@iiug.org [ids-bounces@iiug.org] on behalf of Paul Watson
> [paul@oninit.com]
> Sent: Thursday, September 09, 2010 6:03 PM
> To: ids@iiug.org
> Subject: Re: wildcard in replace function? [21217]
>
> Have you looked the Regular Expression data blade ?
>
> Paul Watson
> Oninit LLC
> Tel: +1 913 674 0360
> Cell: +1 913 387 7529
>
> Failure is not as frightening as regret
>
> On 9 Sep 2010, at 16:38, "Fernando Nunes" <domusonline@gmail.com> wrote:
>
>> On Thu, Sep 9, 2010 at 6:28 PM, Wyza, Jonathon
> <wyzaj@bethelcollege.edu>wrote:
>>
>>> Is it possible to use a wildcard in the replace function?
>>>
>>> I was trying something like this:
>>>
>>> replace(value, "*@", "")
>>>
>>> which would replace everything up to and including the @ with nothing.
>>> But
>>> no
>>> dice. I also tried % but that didn't fly either. Thoughts?
>>>
>>>
>> The following seems to work, but it's not very elegant... I have the
>> feeling
>> I've seen better, but that's what I could come up for now... Maybe
>> others
>> can embarrass me :):
>>
>>
>>
>
>
--------------------------------------------------------------------------------
----------------------------------------
>> cheetah@pacman.onlinedomus.net:fnunes-> dbaccess stores <<EOF
>>> CREATE PROCEDURE trunc_left( str VARCHAR(255), c CHAR) RETURNING>> VARCHAR(255);
>>>
>>> DEFINE i SMALLINT;
>>>
>>> FOR i = 1 TO LENGTH(str)
>>>
>>> IF substr(str,i,1) = c
>>> THEN
>>> LET str = substr(str,i,LENGTH(str) - i + 1 );
>>> RETURN str;
>>> END IF;
>>> END FOR;
>>> END PROCEDURE;
>>>
>>> EXECUTE PROCEDURE trunc_left('Blah blah@and more blah blah!','@');>>> EOF
>>
>> Database selected.
>>
>> Routine created.
>>
>> (expression) @and more blah blah!
>>
>> 1 row(s) retrieved.
>>
>> Database closed.
>>
>>
>>
>
>
--------------------------------------------------------------------------------
----------------------------------------
>> Regards.
>>
>>> Jonathon Wyza
>>> CX & CBORD System Administrator
>>> CX Programmer/Analyst
>>> Administrative Computing
>>> Bethel College
>>> (574)-257-3381
>>> AIM: Iamwyza
>>> jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu>
>>> ==============================
>>> SLES 11x64 & IDS 11.50.FC6
>>>
>>> "Don't document the problem, fix it."
>>> - Atli Björgvin Oddsson
>>>
>>>
>>>
>>>
>>
>
>
*******************************************************************************
>>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>>
>>>
>>
>> --
>> Fernando Nunes
>> Portugal
>>
>> http://informix-technology.blogspot.com
>> My email works... but I don't check it frequently...
>>
>> --0016364ef503183668048fda74c5
>>
>>
>>
>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
--
Paul Watson
Tel: +1 913-674-0360
Mob: +1 913-387-7529
Web: www.oninit.com
www.advancedatatools.com
Failure is not as frightening as regret.
If you want to improve, be content to be thought foolish and stupid.
Agreed. We use it here on HPUX. Let me know if you have any questions.
Thank you,
Jim Goldrick
Judson University
573-332-7739
http://www.judsonu.edu
jgoldrick@judsonu.edu
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Paul
Watson
Sent: Thursday, September 09, 2010 5:35 PM
To: ids@iiug.org
Subject: RE: wildcard in replace function? [21219]
Its free and one of the most useful you can install
Cheers
Paul
> I've never used any data blades, I don't even know if we are licensed for
> them.
>
> Jonathon Wyza
> CX & CBORD System Administrator
> CX Programmer/Analyst
> Administrative Computing
> Bethel College
> (574)-257-3381
> AIM: Iamwyza
> jonathon.wyza@bethelcollege.edu
> ==============================
> SLES 11x64 & IDS 11.50.FC6
>
> "Don't document the problem, fix it."
> - Atli Björgvin Oddsson
>
> ________________________________________
> From: ids-bounces@iiug.org [ids-bounces@iiug.org] on behalf of Paul Watson
> [paul@oninit.com]
> Sent: Thursday, September 09, 2010 6:03 PM
> To: ids@iiug.org
> Subject: Re: wildcard in replace function? [21217]
>
> Have you looked the Regular Expression data blade ?
>
> Paul Watson
> Oninit LLC
> Tel: +1 913 674 0360
> Cell: +1 913 387 7529
>
> Failure is not as frightening as regret
>
> On 9 Sep 2010, at 16:38, "Fernando Nunes" <domusonline@gmail.com> wrote:
>
>> On Thu, Sep 9, 2010 at 6:28 PM, Wyza, Jonathon
> <wyzaj@bethelcollege.edu>wrote:
>>
>>> Is it possible to use a wildcard in the replace function?
>>>
>>> I was trying something like this:
>>>
>>> replace(value, "*@", "")
>>>
>>> which would replace everything up to and including the @ with nothing.
>>> But
>>> no
>>> dice. I also tried % but that didn't fly either. Thoughts?
>>>
>>>
>> The following seems to work, but it's not very elegant... I have the
>> feeling
>> I've seen better, but that's what I could come up for now... Maybe
>> others
>> can embarrass me :):
>>
>>
>>
>
>
--------------------------------------------------------------------------------
----------------------------------------
>> cheetah@pacman.onlinedomus.net:fnunes-> dbaccess stores <<EOF
>>> CREATE PROCEDURE trunc_left( str VARCHAR(255), c CHAR) RETURNING>> VARCHAR(255);
>>>
>>> DEFINE i SMALLINT;
>>>
>>> FOR i = 1 TO LENGTH(str)
>>>
>>> IF substr(str,i,1) = c
>>> THEN
>>> LET str = substr(str,i,LENGTH(str) - i + 1 );
>>> RETURN str;
>>> END IF;
>>> END FOR;
>>> END PROCEDURE;
>>>
>>> EXECUTE PROCEDURE trunc_left('Blah blah@and more blah blah!','@');>>> EOF
>>
>> Database selected.
>>
>> Routine created.
>>
>> (expression) @and more blah blah!
>>
>> 1 row(s) retrieved.
>>
>> Database closed.
>>
>>
>>
>
>
--------------------------------------------------------------------------------
----------------------------------------
>> Regards.
>>
>>> Jonathon Wyza
>>> CX & CBORD System Administrator
>>> CX Programmer/Analyst
>>> Administrative Computing
>>> Bethel College
>>> (574)-257-3381
>>> AIM: Iamwyza
>>> jonathon.wyza@bethelcollege.edu<mailto:jonathon.wyza@bethelcollege.edu>
>>> ==============================
>>> SLES 11x64 & IDS 11.50.FC6
>>>
>>> "Don't document the problem, fix it."
>>> - Atli Björgvin Oddsson
>>>
>>>
>>>
>>>
>>
>
>
*******************************************************************************
>>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>>
>>>
>>
>> --
>> Fernando Nunes
>> Portugal
>>
>> http://informix-technology.blogspot.com
>> My email works... but I don't check it frequently...
>>
>> --0016364ef503183668048fda74c5
>>
>>
>>
>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
--
Paul Watson
Tel: +1 913-674-0360
Mob: +1 913-387-7529
Web: www.oninit.com
www.advancedatatools.com
Failure is not as frightening as regret.
If you want to improve, be content to be thought foolish and stupid.
*******************************************************************************
Forum Note: Use "Reply" to post a response in the discussion forum.