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.
Something like this should work:

```
import re,sys

f = open( sys.argv[1], 'r' )
for i in f:
    g = re.match( r'REPLACE\((.*)\)(.*)', i )
    if g is None:
        print i
    else:
        print '<replace name=\"%s\">%s</replace>' % (g.group(1),g.group(2))
f.close()

```