gcue Posted September 10, 2023 Posted September 10, 2023 (edited) Hello world, I am trying to get the all SRC urls from a site Here a sample output. The img class changes (always alpha numeric) so I need to account for those img classes. <div class="kCmkOe"><img class="DS1iW" alt="" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSvnd-L4AgjeXudXN-UNeFeh8lJDSNpmJh_XmNB7OmhB5ixvJfzxXsG8u49OeI&s"/></div> This code works, I get the links I want, but the output also includes all the img classes too $aMetas = StringRegExp($sData, '<img class="([\w\d]*)" alt="" src="([\H]*)"', 3) How do I get just the SRC urls that start with http? if I add "http" to the pattern it wont return http with the results $aMetas = StringRegExp($sData, '<img class="([\w\d]*)" alt="" src="http([\H]*)"', 3) Thank you in advance!! Edited September 11, 2023 by gcue
Solution Andreik Posted September 11, 2023 Solution Posted September 11, 2023 (edited) You just need to declare the class group as non capturing group. <img class="(?:[\w\d]*)" alt="" src="([\H]*)" Or you can use \K to ignore everything before your src. You have multiple ways to achieve that. Maybe something more compact: <img(?:.+)src="(.*)" Not sure what do you mean . Quote SRC urls that start with http Https also start with http. Do you want that too? Edited September 11, 2023 by Andreik
gcue Posted September 11, 2023 Author Posted September 11, 2023 works great! thank you for the explanation also! hope you have a great rest of the weekend
gcue Posted September 11, 2023 Author Posted September 11, 2023 8 minutes ago, Andreik said: Not sure what do you mean . Https also start with http. Do you want that too? there were some img srcs that didnt have a full http path. not sure if it was just the site i was looking at have what i need now - thank you again!!!
Andreik Posted September 11, 2023 Posted September 11, 2023 Awesome. I slightly modified the pattern in the previous example just in case you have an empty string as src. <img(?:.+)src="(.*)"
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