Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? %@ReReplace a quote [SOLVED] [ANSWER: use \q for quotes!]

Jul
534
10
For the life of me... i can't get %@ReReplace to replace a quote with %27

The quote mark throws it off. Using @CHAR[27] doesn't help. Using setdos /x-7 doesn't help.

There just seems to be no way to use @ReReplace to replace a quote mark, and if you ask me, it really oughtta be an example on the doc page
 
What's the problem?

Code:
v:\> set string=a"b

v:\> echo %string
a"b

v:\> echo %@rereplace["^q",xx,%string]
axxb

v:\> set string="ab"

v:\> echo %string
"ab"

v:\> echo %@rereplace["^q",xx,%string]
xxabxx
 
To replace one character with another, regular expressions seem like overkill.

Code:
C:\>set string=Daddy"s home!

C:\>echo %string
Daddy"s home!

C:\>echo %@replace[^q,',%string]
Daddy's home!

C:\>
 
So the answer is use \q not "

over 30 years of regex and i've never used \q , so there you go
 
To replace one character with another, regular expressions seem like overkill.

Code:
C:\>set string=Daddy"s home!

C:\>echo %string
Daddy"s home!

C:\>echo %@replace[^q,',%string]
Daddy's home!

C:\>
Charles, I see that you didn't quote the ^q in the regex. That doesn't seem dependable here.

Code:
v:\> echo %string
a"b"c"

v:\> echo %@rereplace[^q,xx,%string]
a"b"c"

v:\> echo %@rereplace["^q",xx,%string]
axxbxxcxx
 
Charles, I see that you didn't quote the ^q in the regex. That doesn't seem dependable here.

I'm not using a regex. I used @REPLACE instead of @REREPLACE, because regexes seem like overkill for this job. Like using a Stinger missile to swat a mosquito.
 
Charles, I see that you didn't quote the ^q in the regex. That doesn't seem dependable here.

Code:
v:\> echo %string
a"b"c"

v:\> echo %@rereplace[^q,xx,%string]
a"b"c"

v:\> echo %@rereplace["^q",xx,%string]
axxbxxcxx
OK, I see. You weren't using @rereplace. But there's still a question. In the example above, without quoting ^q, no amount of escaping the 'q' works.

Code:
v:\> echo %@rereplace[^q,xx,%string]
a"b"c"

v:\> echo %@rereplace[^^q,xx,%string]
a"b"c"

v:\> echo %@rereplace[^^^q,xx,%string]
a"b"c"

v:\> echo %@rereplace[^^^^q,xx,%string]
a"b"c"
 
Now it's a race to see who can escape it first

An "escape room", if you will
 
Back
Top