[Tutor] simple search and replace...
Lie Ryan
lie.1296 at gmail.com
Sat Apr 3 11:04:04 CEST 2010
On 04/01/10 06:51, ALAN GAULD wrote:
> But if it's fixed patterns you can either do a replace()
> in a loop over your patterns:
>
> for pat in ['PID','OBR',.....]
> h7string = h7string.replace('\n'+pat, h7string)
>
> Or even build a regex that does it all in one.
> (But the regex could get complex quickly!)
Or even write a "regex precompiler" that converts a list of items to
search into regex string (read: '|'.join(keywords)). That may be
necessary depending on the complexity of your queries and your
clash-handling scenario (what would you like to happen if your
replacement string contains another string in the keywords?).
More information about the Tutor
mailing list