You must be scraping the site log.
Since you're importing data into a database, why bother with text replacement?
Just do a join on the source / target IDs with your list of group and user IDs with labels.
The format of the site logs are:
time-stamp, site, action, source type, source ID, target type, target ID, LCN, call type.
Example:
20140629154211,1,Logout,I,73, ,0,0,
20140629154212,1,Call,I,15001,G,5520,618, -
20140629154213,1,Call,I,11791,G,13872,642, -
20140629154213,1,Call,I,7229,G,11344,705, -
20140629154214,1,Call,I,14581,G,11376,665, -
Using this as a working example ..
20140629154213,1,Call,I,7229,G,11344,705, -
The "I" before 7229 tells you that 7229 is a radio ID.
The "G" before 11344 tells that 11334 is a group ID.
So ... you have the ID and you can tell group IDs from user IDs.
Look at Brandon's annotation utility - which reads the site log and the XML to add labels.
http://k7bbr.net/projects/utmerge.htm