I am trying to parse the output of a Windows command prompt command that gets the Caption and ProcessId of child processes for a process. The command returns output in the following format:
Caption ProcessId\r\r\nnotepad++.exe 40000 \r\r\nnfilezilla.exe 90000 \r\r\n\r\r\n
The regex I am trying to use is:
Caption\s*ProcessId((?:\r\r\n)([a-zA-z\W]+.exe)\s*(\d+)\s*)*
Here is what I am trying to do:
- Match the start of the output
Caption ProcessId - Capture the caption and process ID of each process in the output
- Using the non-capture group, match the two carriage returns
\rand single newline character\nthat precedes the process information. - Within the first capture group, capture the caption of the process
- Match any whitespace between the caption and process ID
- Within the second capture group, capture the process ID
- Continue matching within the non-capture group zero or more times
- Using the non-capture group, match the two carriage returns
I have been using https://regex101.com/r/Zqo6FW/47 with the regex and example string I used above. Doing so, I match only Caption ProcessId and I can't seem to match the carriage returns and newline characters.
How can I modify my regex to successfully match the example output?
cmdtag is related to Microsoft Windows cmd.exe. If this is not about Windows, please remove thecmdtag.