Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Simple regular expression question

Reply
 
Old 10-14-2009   #1 (permalink)
Gabriela


 
 

Simple regular expression question

Hi,

I'd like to write a regexp that finds matches to all URLs (strings)
that have the following:
http://ads.[domain].com
whereas:
domain can be any domain name.
com - can be any extension (com, co.uk, it...)

Any ideas?
Thanks,
Gabi,

My System SpecsSystem Spec
Old 10-14-2009   #2 (permalink)
ekkehard.horner


 
 

Re: Simple regular expression question

Gabriela schrieb:
Quote:

> Hi,
>
> I'd like to write a regexp that finds matches to all URLs (strings)
> that have the following:
> http://ads.[domain].com
> whereas:
> domain can be any domain name.
> com - can be any extension (com, co.uk, it...)
[...]
Dim sTest : sTest = Join( Array( _
"Assuming your data is like HTML, the urls should be quoted. Then" _
, "the regex should find ""http://ads.domain.ext"" but not ""http://sad.domain.ext""." _
, "Add more samples like <a href=""http://ads.domain.ext/index.html?a=b&c=d""
whatever>," _
, "or ""https://ads.domain.ext"" or ""http://adsx.domain.ext"" to see whether and
where" _
, "more tinkering with the pattern is needed." _
), vbCrLf )
WScript.Echo sTest
Dim reUrl : Set reUrl = New RegExp
reUrl.Global = True
reUrl.IgnoreCase = True
reUrl.Pattern = """(http://ads\.[^""]+)"""
Dim oMTS : Set oMTS = reUrl.Execute( sTest )
Dim oMT
For Each oMT In oMTS
WScript.Echo oMT.SubMatches( 0 )
Next

output:

=== findUrls: find urls using regexp ==========================================
Assuming your data is like HTML, the urls should be quoted. Then
the regex should find "http://ads.domain.ext" but not "http://sad.domain.ext".
Add more samples like <a href="http://ads.domain.ext/index.html?a=b&c=d" whatever>,
or "https://ads.domain.ext" or "http://adsx.domain.ext" to see whether and where
more tinkering with the pattern is needed.
http://ads.domain.ext
http://ads.domain.ext/index.html?a=b&c=d
=== findUrls: 0 done (00:00:00) ===============================================
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Regular Expression help C# .NET General
Regular Expression Question PowerShell
Help with a regular expression VB Script
Simple Regular Expression PowerShell
simple regular expression PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46