FINDSTR + literal strings/double quotes and DelayedExpansion

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: FINDSTR + literal strings/double quotes and DelayedExpan

#16 Post by Squashman » 20 Mar 2014 09:17

©opy[it]®ight wrote: (reading this, Squashman? :wink: ).

Reading your own threads was not the point I was making with my comment above.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: FINDSTR + literal strings/double quotes and DelayedExpan

#17 Post by penpen » 20 Mar 2014 11:53

©opy[it]®ight wrote:I hope this stuff didn't keep you from sleeping? :P
Thanks, but you can be sure it won't. :)

©opy[it]®ight wrote:Does this escape all known (to-be-escaped) characters or is there more to it?
There are more ('^'. '.', '\<', '\>' ), and i cheated with the dot ('.') character (actually accepts any character at the position the dot holds):
Should be escaped to '\.' (set "searchStringR%%a=!searchStringR%%a:.=\.!") when using regular expressions.

I also have tricked when escaping the asterisk ('*') to be able to replace it in strings easily.

But as i've written above it's just an example; it should only show how to escape a string when using findstr.
I'm even not sure if such an automation is really needed, as escaping is not that hard.

penpen

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: FINDSTR + literal strings/double quotes and DelayedExpan

#18 Post by Squashman » 10 Nov 2016 10:44

penpen wrote:I also have tricked when escaping the asterisk ('*') to be able to replace it in strings easily.


Hi Penpen,
Could you explain what you meant with this comment.

Thanks.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: FINDSTR + literal strings/double quotes and DelayedExpansion

#19 Post by penpen » 10 Nov 2016 12:25

Whenever a search string shall contain a simple asterisk ('*'), i have used an asterisk preceeded by a circumflex accent ('^') instead;
then i can replace the asterisks easily by replacing "^*" instead, for example:

Code: Select all

@echo off
:: desired search string "1*2"
set "string=1^*2"
echo %string:^*=\*%


penpen

Post Reply