How to use findstr on path to output certain folders

  cmd, regex, windows

I want to come up with a command that searches my path variable and outputs the folders that include the search keyword. For example: I want to output all paths included in my path variable that include the word ‘python’ (case insensitive).

My path looks like this:

C:Program FilesConEmuConEmuScripts;C:Program
FilesConEmu;C:Program FilesConEmuConEmu;C:Program
FilesAdoptOpenJDKjre-11.0.4.11-hotspotbin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program
FilesMicrosoft VS Codebin;C:Program Files
(x86)PDFtkbin;C:Program Filesffmpegbin;C:Program
Filesffmpegavconvbin;C:Program Filesffmpegcurlbin;C:Program
Filesnodejs;C:Program FilesGitcmd;C:Program Files
(x86)Gpg4win..GnuPGbin;C;C:UsersjcAppDataLocalProgramsPythonPython38-32Scripts;C:UsersjcAppDataLocalProgramsPythonPython38-32;C:UsersjcAppDataRoamingnpm;C:Program
FilesOpenSSH;C:Usersjc.ssh;C:Program Files
(x86)Nmap;C:/Users/jc/AppData/Local/Programs/Python/Python38-32/python.exe;

Expected result would be:

C:UsersjcAppDataLocalProgramsPythonPython38-32Scripts;C:UsersjcAppDataLocalProgramsPythonPython38-32;C:/Users/jc/AppData/Local/Programs/Python/Python38-32/python.exe;

So far, I have a regex formula that selects every path (see example here). The regex I have is:

C.*?;gmi

If I try
path | findstr "C.*?;"

Nothing really comes out (shouldn’t it output all lines that match that regex?). Also, how would I go about outputting the paths that include the intended search keyword? Thanks

Source: Windows Questions

LEAVE A COMMENT