Question: I'm using Python to write a regular expression for replacing parts of the string with a XML node.

The source string looks like:

```

Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace

```

And the result string should be like:

```

Hello
<replace name="str1"> this is to replace </replace>
<replace name="str2"> this is to replace </replace>

```

Can anyone help me?

Answer: 
Here is an [excellent tutorial](http://www.amk.ca/python/howto/regex/) on how to write regular expressions in Python.
```
import re

a="""Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace"""

regex = re.compile(r"^REPLACE\(([^)]+)\)\s+(.*)$", re.MULTILINE)

b=re.sub(regex, r'< replace name="\1" > \2 < /replace >', a)

print b

```

will do the replace in one line.