Page 1 of 1

SC replace allow NoAutoWildcards option

Posted: 27 May 2013 20:25
by serendipity
I am trying a way to force exact match in SC replace, but as i see it, its not supported. For example this:

Code: Select all

$text="dp12,dp13,dp14,dp1,dp15"; $text = replace ($text, "dp1", "gp1"); text $text;
will replace all "dp1" occurence with "gp1" which results in "gp12,gp13...." but i want exact match.
Could there be a NoAutoWildcards option?

Re: SC replace allow NoAutoWildcards option

Posted: 27 May 2013 20:32
by admin
That would be replace with "Whole Words" options. No, that's not available at the moment. But "regexreplace" can probably do it.

Re: SC replace allow NoAutoWildcards option

Posted: 27 May 2013 20:39
by serendipity
admin wrote:That would be replace with "Whole Words" options. No, that's not available at the moment. But "regexreplace" can probably do it.
OK, no issues.

Re: SC replace allow NoAutoWildcards option

Posted: 28 May 2013 12:17
by PeterH
serendipity wrote:I am trying a way to force exact match in SC replace, but as i see it, its not supported. For example this:

Code: Select all

$text="dp12,dp13,dp14,dp1,dp15"; $text = replace ($text, "dp1", "gp1"); text $text;
will replace all "dp1" occurence with "gp1" which results in "gp12,gp13...." but i want exact match.
Could there be a NoAutoWildcards option?
Why not:

Code: Select all

$text = replace ($text, ",dp1,", ",gp1,");
But: first you must add "," to beginning and end of $text, and at the end strip it again, else occurence in very first and very last position will not be recognized, about:

Code: Select all

$text = trim(replace (",$text,", ",dp1,", ",gp1,"), ",";
But pay attention: if the very first or very last character is ',' it might get lost? (Didn't test...)

Re: SC replace allow NoAutoWildcards option

Posted: 28 May 2013 17:43
by serendipity
PeterH wrote:
serendipity wrote:I am trying a way to force exact match in SC replace, but as i see it, its not supported. For example this:

Code: Select all

$text="dp12,dp13,dp14,dp1,dp15"; $text = replace ($text, "dp1", "gp1"); text $text;
will replace all "dp1" occurence with "gp1" which results in "gp12,gp13...." but i want exact match.
Could there be a NoAutoWildcards option?
Why not:

Code: Select all

$text = replace ($text, ",dp1,", ",gp1,");
But: first you must add "," to beginning and end of $text, and at the end strip it again, else occurence in very first and very last position will not be recognized, about:

Code: Select all

$text = trim(replace (",$text,", ",dp1,", ",gp1,"), ",";
But pay attention: if the very first or very last character is ',' it might get lost? (Didn't test...)
Thanks PeterH! I tried a variation of this yesterday. Just searched for "dp1," and replaced with "gp1,"

Re: SC replace allow NoAutoWildcards option

Posted: 28 May 2013 23:14
by PeterH
serendipity wrote:Thanks PeterH! I tried a variation of this yesterday. Just searched for "dp1," and replaced with "gp1,"
OK: if you
- don't have an entry named xdp1,
- and if the searched entry is never the last
then it's OK.

Re: SC replace allow NoAutoWildcards option

Posted: 28 May 2013 23:22
by serendipity
PeterH wrote:
serendipity wrote:Thanks PeterH! I tried a variation of this yesterday. Just searched for "dp1," and replaced with "gp1,"
OK: if you
- don't have an entry named xdp1,
- and if the searched entry is never the last
then it's OK.
For something i was trying yesterday this worked fine, but you are right, better to cover it all in first go than regret later.
So your method is sort of more foolproof. Thanks! :)