SC replace allow NoAutoWildcards option

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

SC replace allow NoAutoWildcards option

Post 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?

admin
Site Admin
Posts: 67247
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: SC replace allow NoAutoWildcards option

Post by admin »

That would be replace with "Whole Words" options. No, that's not available at the moment. But "regexreplace" can probably do it.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SC replace allow NoAutoWildcards option

Post 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.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: SC replace allow NoAutoWildcards option

Post 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...)

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SC replace allow NoAutoWildcards option

Post 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,"

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: SC replace allow NoAutoWildcards option

Post 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.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SC replace allow NoAutoWildcards option

Post 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! :)

Post Reply