mariasx Posted October 17, 2009 Share Posted October 17, 2009 (edited) I would like to extract SRC value from IMG tag.regexp patern is: "src=(.*?) .*?>"this regexp pattern match: <img src="/Client.Images/Society/facebook.gif" alt="" /><img src="/Client.Images/Society/facebook.gif" alt=""/><img src="/Client.Images/Society/facebook.gif" />this regexp patern do not match when SRC is last value and space character is missing before tag is closed:<img src="/Client.Images/Society/facebook.gif"/>thanks for help Edited October 17, 2009 by mariasx Link to comment Share on other sites More sharing options...
Gabriel13 Posted October 17, 2009 Share Posted October 17, 2009 It looks like this should work: msgbox(0,default,stringRegExp('<img src="/Client.Images/Society/facebook.gif"/>','src="(.*)".*>')) ; returns 1 (true) …with the added benefit that it removes the quotes from the captured value, too. [url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url] Link to comment Share on other sites More sharing options...
BugFix Posted October 17, 2009 Share Posted October 17, 2009 Or so: $str = '<img src="/Client.Images/Society/facebook.gif"/>' $pattern = '(<img src=")([^"]*)(.+)' ConsoleWrite('src=' & StringRegExpReplace($str, $pattern, '$2') & @CRLF) Best Regards BugFix Link to comment Share on other sites More sharing options...
mariasx Posted October 17, 2009 Author Share Posted October 17, 2009 It looks like this should work: msgbox(0,default,stringRegExp('<img src="/Client.Images/Society/facebook.gif"/>','src="(.*)".*>')) ; returns 1 (true) …with the added benefit that it removes the quotes from the captured value, too. Gabriel, this is great. Thanx. I did not want remove quotes, because quotes are missing on some websites: <img src=facebook.gif> And one more benefit for me: Till today I did not know that apostrofe could be used instead of quotes. Great. Thanx Link to comment Share on other sites More sharing options...
mariasx Posted October 17, 2009 Author Share Posted October 17, 2009 Or so: $str = '<img src="/Client.Images/Society/facebook.gif"/>' $pattern = '(<img src=")([^"]*)(.+)' ConsoleWrite('src=' & StringRegExpReplace($str, $pattern, '$2') & @CRLF) BugFix, Your pattern looking pretty difficult. I have to learn hard. Thank you. Link to comment Share on other sites More sharing options...
BugFix Posted October 17, 2009 Share Posted October 17, 2009 For better learning i'll comment it: $pattern = '(<img src=")([^"]*)(.+)' By working with StringRegExpReplace you need in most cases backreferences. Backreferences are created by using round brackets. (<img src=") <== the first backreference - unneed later ([^"]*) <== the second backreference (every char that NOT ", any times) - we need (.+) <== the third backreference (any char, any times) - unneed later Replace value: '$2' <== it means, that string will replaced with second backreference Best Regards BugFix Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now