For some reason I'm unable to grok Python's string.replace( ) function.
Just trying to parse a simple IP address, wrapped in square brackets,
from Postfix logs. In sed this is straightforward given:
line = "date process text [ip] more text"
sed -e 's/^.*\[//' -e 's/].*$//'
yet the following Python code does nothing:
line = line.replace('^ .*\[', '', 1)
line = line.replace('].*$', '')
Is there a decent description of string.replace( ) somewhere?
Raymond
Just trying to parse a simple IP address, wrapped in square brackets,
from Postfix logs. In sed this is straightforward given:
line = "date process text [ip] more text"
sed -e 's/^.*\[//' -e 's/].*$//'
yet the following Python code does nothing:
line = line.replace('^ .*\[', '', 1)
line = line.replace('].*$', '')
Is there a decent description of string.replace( ) somewhere?
Raymond
Comment