PDA

View Full Version : Little Regex Problem



cosmarchy
04-09-2011, 10:04 AM
Hi,
I am looking for some help with a regex. Basically all I want is a regex which returns the square brackets from a string.

So far I have this:

Private Sub FindBrackets()
Dim Regex As RegExp
Dim Matches As Variant
Dim v As Variant
Dim strString As String

Set Regex = New VBScript_RegExp_55.RegExp

On Error Resume Next

Regex.IgnoreCase = True
Regex.Global = True

Regex.Pattern = "\[([^\x22]*\])*"
strString = "hello [test][testing] world"

Set Matches = Regex.Execute(strString)

For Each v In Matches
Debug.Print v
Next
End Sub
The array matches only returns [test] [testing] however I want these separately not together ie different elements in the matches array so I can iterate through later on. In between the square brackets could be either text or numbers maybe a dash...:dunno

If anyone can help me out I would appreciate it.

Many thanks

mancubus
04-09-2011, 11:34 AM
hi.

maybe this will not help you but may provide info (if you need...)

http://www.vbaexpress.com/kb/getarticle.php?kb_id=68
open the word doc in worksheet introduction.