I am searching a folder looking for files which contain the word car
. This is a sample of the data I'm working with, obtained by using the findstr
utility - findstr /s /i /n car *.*
interview-290346:1:Drives a similar car to the description.
interview-29316965:3:time.) 'You're nothing but a pack of cards!'
interview-676473:7:The next witness was the Duchess's cook. She carried the pepper-box in
interview-3804339:1:Park's car is red, not blue, and the person on the camera is presumed to be male. Not considered a suspect.
I want to find the files which contain the word car
, but not words which contain the substring car
. I have tried to use the findstr
utility with the regex car\b
but I can't work out how to escape it properly. None of the below return any results:
findstr /s /i /n car\b *.*
findstr /s /i /n "car\b" *.*
findstr /s /i /n car\\b *.*
findstr /s /i /n car\\\\b *.*
findstr /s /i /n "car\\b" *.*
findstr /s /i /n "car\\\\b" *.*
What is the correct way to escape the regex, and is there something else I need to do in order to use it within findstr
? (I did notice after typing this that the regex will still match words with the car
substring at the end of the word, but that's ok. My question isn't about what regex to use, but how to escape it for use in findstr
.)
(If anyone is interested in the context of this question, I'm working through the Command Line murder mystery.)
Judging by the documentation, findstr doesn't understand \b. You could use an inverse class instead, e.g. "car[^a-z]" (untested), although that wouldn't match if "car" was the last thing in the file. (You could maybe invoke findstr with a different expression to catch those.)