You probably want to use the -match operator, along with a capturing regular expression. Once run, the built-in $matches variable will contain the captured values. This isn't necessarily easy stuff, but broadly speaking...
"return code (?\d)"
"return code " precedes what you want to capture, and so the (?\d) part would capture a single digit in a named capture group, named "code."
http://www.heikniemi.net/hardcoded/2010/02/powershell-basics-4-matching-and-capturing-with-regular-expressions/ might have some more useful detail. There are some great examples.