Extracting a URL using a regular expression

时间:2015-07-29 00:34:44

标签: regex excel vba excel-vba outlook

I receive 10 or 12 emails from the same website and I would like to extract a particular URL using regex (if possible) and have it pasted into the correct Excel file. The e-mails are in Outlook and I already have a VBA script (that runs from Outlook VBA) that I used to extract the Subject and Sender. However, I really need that particular URL in each e-mail to be the third piece of information extracted.

I have tried to create a series of steps to:

  1. create the RegEx
  2. apply the RegEx to the current email
  3. place the extracted URL into the excel document.

However, whatever I have created fails miserably. The VBA pasted below always worked until I wrote in the additional RegEx part.

I believe I have the correct pattern:

fooSync.config(function($stateProvider, $urlRouterProvider)
{
$urlRouterProvider.otherwise('/login')

...

$stateProvider.state('login',
{
    url: '/login',
    views:
    {
        settings:
        {
            templateUrl: 'login.html'
        }
    }
})
})

Whenever I run the new VBA script, it doesn't do anything. The old code always worked. The code is written into This Outlook Session (just to clarify) because the mailitem needs to run from a script.

/http:\/\/www.changedetection.com\/log(.*)/ig

1 个答案:

答案 0 :(得分:1)

VBScript regex patterns don't use CONVERT(DECIMAL(8, 2), SUM([can]/1.2)) + SUM([carton]/1.2)) AS [N], to indicate the start and end. Nor do they use / or i after the trailing g to indicate case-insensitivety or globalness. Instead, use the / and IgnoreCase properties.

For example:

Global

Here's a great reference if you're looking for more information about the With Reg1 .Pattern = "http://www\.changedetection\.com/log(.*)" .IgnoreCase = True .Global = True End With object.