Jump to content

Recommended Posts

Posted (edited)

#include <Array.au3>

$sString = '<a href="http://www.google.com" target="_blank">Google</a> <a rel="nofollow" href="http://maps.google.com" target="_blank">Google Maps</a>'
$aLink = StringRegExp($sString, 'href="(.+)" target', 3)
_ArrayDisplay($aLink, 'aLink')
Result: http://www.google.com" target="_blank">Google</a> <a rel="nofollow" href="http://maps.google.com

 

But I want: http://www.google.com

 

He should stop by the first 'target' not by the last, how I get that?

Edited by nyke0
Posted (edited)

?

#include <Array.au3>
 
$sString = '<a href="http://www.google.com" target="_blank">Google</a> <a rel="nofollow" href="http://maps.google.com" target="_blank">Google Maps</a>'

$aLink = StringRegExp($sString, 'href="([^"]+)', 1)
_ArrayDisplay($aLink, 'aLink')

To get both links, put a 3 instead of 1 as last parameter

Edit

To make your expression work, you must use the lazy quantifier '?'

$aLink = StringRegExp($sString, 'href="(.+?)" target', 3)
Edited by mikell

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...