0

I need to specify a regular expression that includes | character to findstr command:

processtext.exe | findstr /R "Hello|Bye"

How do I escape it? \| does not work. Quotes fix issue with pipelining but the regex does not match although separate searches for "Hello" and "Bye" do. I'm interested in a solution for legacy shell, not powershell.

UserControl
  • 135
  • 1
  • 6
  • Have you tried encapsulating it in quotation marks? What does your entire script look like? – Reaces Feb 20 '15 at 09:24
  • Are you sure findstr supports pipe syntax (this|that matching)? Not seeing anything in the documentation. – Dan Feb 20 '15 at 09:42
  • 2
    [FINDSTR support for regular expressions is limited and non-standard](http://ss64.com/nt/findstr.html). FINDSTR does not support alternation with the `|` pipe character... – JosefZ Feb 20 '15 at 13:14

2 Answers2

-1

I've found a solution for my purposes of running powershell commands from cmd.exe as follows:

C:\GitLab-Runner>powershell get-service *gitlab* ^| ft

to get following output

Status   Name               DisplayName
------   ----               -----------
Stopped  gitlab-runner      gitlab-runner
Jochen
  • 169
  • 1
  • 3
  • This doesn't even remotely address the question. – Gerald Schneider Jun 01 '23 at 16:44
  • The point is that using `^|` worked for my command to escape the pipe character correctly. At least, it is a chance that the `^` char works for your requirement, too. If not, this answer might at least be helpful for other persons searching for a solution in combination with other commands (like `powershell`). – Jochen Jun 01 '23 at 17:00
  • For your reference, you might want to take a look at https://stackoverflow.com/questions/1200235/how-to-pass-a-quoted-pipe-character-to-cmd-exe which provides some solutions for similar challenge – Jochen Jun 01 '23 at 17:23
-1

If someone is still interested just replace the pipe with a space, like in findstr /R "Hello Bye".

Zalam
  • 1