Try this regex:
(?!<id>)http:\/\/(.*?)\.com(?=<\/id>)
Instead of:
(?<id>)http://(.*?).com(?=</id>)
see demo here: http://regex101.com/r/xH8mH7
Question
I am trying to build a list of urls contained in an xml document where I am matching everything inside of <id>http://xxx.xxxx.com</id>
and I'm having trouble.
I'm trying to match this pattern: /(?<id>)http://(.*?).com(?=</id>)/g
It works on regexr.com but I cannot seem to get it to work with my jsfunction:
var regEx = new RegExp('/(?<id>)http://(.*?).com(?=</id>)/g');
I am getting an error:
SyntaxError: Invalid regular expression: //(?<id>)http://(.*?).com(?=</id>)/g/: Invalid group
Solution
Try this regex:
(?!<id>)http:\/\/(.*?)\.com(?=<\/id>)
Instead of:
(?<id>)http://(.*?).com(?=</id>)
see demo here: http://regex101.com/r/xH8mH7
OTHER TIPS
Try DOMParser ;
// Code tested under Firefox 27
var doc = new DOMParser()
.parseFromString('<id>http://xxx.xxxx.com</id>', "application/xml");
var ids = doc.querySelectorAll('id'); // Return: NodeList[id]
However it doesn't work in IE <= 8 (Browser compatibility)