In sentences like:
"[x] Alpha
[33] Beta
I retrieve the data array in brackets as ([x], [33])
using the VBA regular expression pattern:
"(\[x\])|(\[\d*\])"
I cannot directly retrieve an array of data without parentheses like (x, 33)
using web resource recommendations for a template
"(?<=\[)(.*?)(?=\])"
Is this a specific VBA problem (that is, restricting the implementation of Regex) or did I misunderstand the "look back and forth"?
Public Function Regx( _
ByVal SourceString As String, _
ByVal Pattern As String, _
Optional ByVal IgnoreCase As Boolean = True, _
Optional ByVal MultiLine As Boolean = True, _
Optional ByVal MatchGlobal As Boolean = True) _
As Variant
Dim oMatch As Match
Dim arrMatches
Dim lngCount As Long
' Initialize to an empty array
arrMatches = Array()
With New RegExp
.MultiLine = MultiLine
.IgnoreCase = IgnoreCase
.Global = MatchGlobal
.Pattern = Pattern
For Each oMatch In .Execute(SourceString)
ReDim Preserve arrMatches(lngCount)
arrMatches(lngCount) = oMatch.Value
lngCount = lngCount + 1
Next
End With
Sub testabove()
Call Regx("[x] Alpha" & Chr(13) & _
"[33] Beta", "(\[x\])|(\[\d*\])")
End Sub
source
share