Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:33:19+00:00 2026-06-03T02:33:19+00:00

I wrote a simple script, using VBA. (I need to optimize some work with

  • 0

I wrote a simple script, using VBA. (I need to optimize some work with excel).

First question about Regex:

As I said before, I used VBA.

Simple task: get a match of pattern and capture the submatches.

my code is:

Dim ResStr as Object
Dim LastStr as Object
Dim RE as Object


Set RE = CreateObject("vbscript.regexp") 'create a regex
With RE
    .MultiLine = False  'm-key
    .Global = False     'g-key
    .IgnoreCase = False 'i-key
    .Pattern = "[<]TD\s+class=gm[>](\d+\.\d+)[<][/]TD[>]" 'tag
End With

Set ResStr = RE.Execute(StrDollar)  'use regex  
Set LastStr = ResStr(0).SubMatches  'get submatch

How do I get the LAST match and LAST submatch? (length-property?)

Second question about Dir function:

How do I filter the files?

I saw this code on msdn:

   ' Display the names in C:\ that represent directories.
   MyPath = "c:\"   ' Set the path.
   MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
   Do While MyName <> ""   ' Start the loop.
     ' Use bitwise comparison to make sure MyName is a directory.
     If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
       ' Display entry only if it's a directory.
       Debug.WriteLine(MyName)
     End If   
     MyName = Dir()   ' Get next entry.
  Loop

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then – stop ‘msdn-guy’! are you kidding? is it ONLY one method?

Is there any possible way to make normal filter, not this tremendous-line method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:33:20+00:00Added an answer on June 3, 2026 at 2:33 am

    To get all matches, submatches, length etc you would use something like this – I have added a working example with a simpler pattern to demonstrate (ie match a sequences of numbers with then a non-number)

    You should Test your regexp before presuming a match has been found to avoid erros

    Sub Test()
    Dim RE As Object
    Dim strSample As String
    Dim ResStr As Object
    Dim LastStr As Object
    strSample = "123dd6789a"
    Set RE = CreateObject("vbscript.regexp")    'create a regex
    With RE
        .MultiLine = False  'm-key
        .Global = True     'g-key
        .IgnoreCase = False    'i-key
        .Pattern = "\d+([^\d])"
    End With
    If RE.Test(strSample) Then
        Set ResStr = RE.Execute(strSample)
        For Each LastStr In ResStr
            MsgBox "Match: " & LastStr & vbNewLine & "SubMatch: " & LastStr.submatches(0) & vbNewLine & "Position: " & LastStr.firstindex + 1 & vbNewLine & "Length: " & LastStr.Length
        Next
    End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a simple thumbnailing script I wrote and it's pretty standard: $imgbuffer =
I wrote a quick script to download files using LWP::Simple library and its getstore()
So I wrote a Python script which does some simple stuff. It was originally
I wrote a simple bash script because I was using a grep command with
I am trying to compile a simple script I wrote using Python3 and PyQt4
I wrote a simple python script using the SocketServer, it works well on Windows,
Using some tutorials I wrote simple widget but it causes error declare customwidget.TestDijit: mixin
I coded a relatively simple script using python and also wrote doc strings for
I wrote a script a while back that would do some simple install procedures
I'm using php-excel-reader 2.21 for converting XLS file to CSV. I wrote a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.