Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
findstr
- Posts: 17
- Joined: 09 Jun 2021 12:36
#1
Post
by findstr » 09 Jun 2021 12:48
Hello!
Code: Select all
C:\>ECHO /? | FINDSTR /R "\s"
ECHO [message]
How does FINDSTR interpret \s regexp?
It produces some strange results, try:
FOR /? | FINDSTR /R "\s"
DIR /? | FINDSTR /R "\s"
netstat -a | FINDSTR /R "\s"
DIR /? | FINDSTR /R "\t"
Produces weird output.
ECHO /? | FINDSTR /R "\t"
Produces no output.
How does it work?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 10 Jun 2021 03:11
Well, you provided some commands. But you didn't tell what output you get, and what output you expected to get. I mean, the findstr command on Windows is probably the tool with the worst regex support out of all regex tools that I know. So, in case you expect that \s will match a whitespace and \t will match a tab, then no, findstr does only support meta characters which are listed in the help message (findstr /?). And half of them are not even "standard regex".
You may want to have a look at JREPL
viewtopic.php?f=3&t=6044
Steffen
-
findstr
- Posts: 17
- Joined: 09 Jun 2021 12:36
#3
Post
by findstr » 10 Jun 2021 11:15
Well, due to localization, the results won't be of any particular use here.
ECHO /? | FINDSTR /R "\s"
returns a single string: ECHO [message]
What results do you get if you run ECHO /? | FINDSTR /R "\s"?
FOR /? | FINDSTR /R "\s"
returns some random strings from FOR's help.
DIR /? | FINDSTR /R "\s"
returns first 2 strings of documentation and 1 string from the middle: " sortorder N..."
What I'm trying to figure out is how exactly findstr interprets \s and is there any good use for \s.
Thanks for JREPL, I'll give it a try!
-
T3RRY
- Posts: 250
- Joined: 06 May 2020 10:14
#4
Post
by T3RRY » 10 Jun 2021 11:49
findstr wrote: ↑10 Jun 2021 11:15
Well, due to localization, the results won't be of any particular use here.
ECHO /? | FINDSTR /R "\s"
returns a single string: ECHO [message]
What results do you get if you run ECHO /? | FINDSTR /R "\s"?
FOR /? | FINDSTR /R "\s"
returns some random strings from FOR's help.
DIR /? | FINDSTR /R "\s"
returns first 2 strings of documentation and 1 string from the middle: " sortorder N..."
What I'm trying to figure out is how exactly findstr interprets \s and is there any good use for \s.
Thanks for JREPL, I'll give it a try!
Had you taken the time to read the documentation of findstr, you would be aware using "\s" with the /R switch is equivalent to just using "s", given the backwards slash is the escape character for findstr meta characters. Given the "s" is just a regular character, the backslash is disregarded.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#5
Post
by aGerman » 10 Jun 2021 11:57
Yeah, also my expectation is that the backslash is simply ignored and findstr tries to match the s in each line.
Tested in a cmd window:
Code: Select all
D:\test>(echo qwe&echo asd&echo yxc)|findstr /r "\s"
asd
D:\test>
Certainly this thread on SO is more enlightening as to further behavior of findstr:
https://stackoverflow.com/questions/884 ... str-comman
Steffen