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.

3
  • Have you tried encapsulating it in quotation marks? What does your entire script look like?
    – Reaces
    Feb 20, 2015 at 9:24
  • Are you sure findstr supports pipe syntax (this|that matching)? Not seeing anything in the documentation.
    – Dan
    Feb 20, 2015 at 9:42
  • 2
    FINDSTR support for regular expressions is limited and non-standard. FINDSTR does not support alternation with the | pipe character...
    – JosefZ
    Feb 20, 2015 at 13:14

2 Answers 2

-1

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

0
-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
3
  • This doesn't even remotely address the question. Jun 1, 2023 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 1, 2023 at 17:00
  • For your reference, you might want to take a look at stackoverflow.com/questions/1200235/… which provides some solutions for similar challenge
    – Jochen
    Jun 1, 2023 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .