Artificial intelligent assistant

Why isn't sed greedy in this simple case? $echo "foo 65 bar" | sed -n -e 's/.*\([0-9]\+\).*/\1/p' 5 Why is the output not `65`? Shouldn't sed greedily match the `[0-9]\+` part? How do I tell sed to match all of `65`?

The `.*` is greedy first -- it's matching `foo 6`. The only reason it stops there is because matching any further would stop the whole pattern from matching, so it leaves the `5` for the `([0-9]+)`. If you made it `([0-9]*)` instead the `.*` would match the whole line and you'd get nothing in your group. One way around it is to tell the first part not to match numbers:


$ echo "foo 65 bar" | sed -n -e 's/[^0-9]*\([0-9]\+\).*/\1/p'
65

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 9c8d258029975cbbeb4e1e48682c7f22