0

I'm pretty new to regex and am having some issues trying to remove 2 strings from a string of text.

I'm using python3 and have tried the following.

'\W*(Command|exited|with|status|0)\W*

To match the string: Command exited with status 0

I am also looking for the regex to match the following.

=== stdout ===

I have tried:

'\W*(===|stdout|===)\W*

Any help with this would be greatly appreciated. Thanks!

revo
  • 47,783
  • 14
  • 74
  • 117
xxen0nxx
  • 87
  • 1
  • 5

1 Answers1

1

Use 'string = re.sub('=== stdout ===', '', string)' to sub your desired text for nothing (''). Here is some example code:

import re

string = 'i think New Roman"=== stdout ===>but I don\'t he=Command exited with status 0"Arial">fun stuff'

string = re.sub('Command exited with status 0', '', string)
string = re.sub('=== stdout ===', '', string)

print(string)

Remember to use '\|' in your string instead of just '|'

  • Downvoted because you replace any instance of “with” or “command”, not the requested string “Command exited with status” – donkopotamus May 23 '18 at 20:13
  • I changed the code slightly to better match the requested string. I did not realize the was using '|' in place of ' '(spaces). – never_comment May 23 '18 at 20:17
  • Thanks guys, let me try this one sec. – xxen0nxx May 23 '18 at 20:47
  • Ok so that did work however I did forget one more, specifically (no stderr), when I tried re.sub('(nostder)', '', string) it works, however, it leaves the () and just removes the nostder. – xxen0nxx May 23 '18 at 20:50