Jump to content

Using StringRegExp patterns twice in a single call


Go to solution Solved by Andreik,

Recommended Posts

Posted (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&amp;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 by gcue
  • gcue changed the title to Using StringRegExp patterns twice in a single call
  • Solution
Posted (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 by Andreik
Posted
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!!!

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
  • Recently Browsing   0 members

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