Sign in to follow this  
Followers 0
mariasx

help with regexp pattern

6 posts in this topic

#1 ·  Posted (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 by mariasx

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

Or so:

$str = '<img src="/Client.Images/Society/facebook.gif"/>'
$pattern = '(<img src=")([^"]*)(.+)'

ConsoleWrite('src=' & StringRegExpReplace($str, $pattern, '$2') & @CRLF)

Best Regards BugFix  

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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  

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0