Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Using javascript instead of regex


Dabrowski - 2:45 pm on Oct 11, 2007 (gmt 0)


Using javascript instead of regex

This title seems strange, why not use a JavaScript regex? The syntax is a little different than whatever you've used, Perl?

Try this, it's untested but should work. If you're familliar with regex's you should recognise the syntax anyway. Note I've changed your double quotes to single for the purpose of containing it within another string.


var text="<img ... src='http://example.com/wigget/red-wigget.jpg' ...>";
text.replace( /^.*src='(.*?)'.*$/, "$1");
alert( text);

You can easily change src to value for the second one, or if you need to use it a lot, use a universal function to extract the parameter you want.


Thread source:: http://www.webmasterworld.com/javascript/3474575.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com