Well you didn't match the end tag so your replace is working as it should, just replacing what you found. Try:
Code:
SurveyID = payload.replace(/<SurveyReference>([^<]+)<\/SurveyReference>/,"$1")
(You'll have to check if \/ is the correct way to escape a / character within a regex.)
I think there are a few simpler ways of finding the ID though.
--
Joe (
Microsoft MVP - XML)