Jump to content

help with regexp pattern


mariasx
 Share

Recommended Posts

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
Link to comment
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]

Link to comment
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

Link to comment
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  

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...