I have a javascript variable, for example:
var s = "<result>Success</result><name>George</name>";
How can I get with javascript regex the result 'Success' and name 'George'?
I have a javascript variable, for example:
var s = "<result>Success</result><name>George</name>";
How can I get with javascript regex the result 'Success' and name 'George'?
You should NOT use regex with XML. Use xml parser http://www.w3schools.com/xml/xml_parser.asp
The regex you are looking for is
var result = s.replace(/.*<result>([^<]*)<\/result>.*/, "$1");
var name = s.replace(/.*<name>([^<]*)<\/name>.*/, "$1");
However, as a general rule of thumb - don't ever use regex to parse HTML. The reason is that the browser already has XML parsers built-in, so why use ugly regex to do something the browser already does?
Parsing XML: http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery
Parsing HTML using the DOM: How to parse HTML from JavaScript in Firefox?