Jump to content
Sign in to follow this  
nyke0

StringRegEXP :/

Recommended Posts

nyke0

#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

Share this post


Link to post
Share on other sites
mikell

?

#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

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  

×