Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 354
- Office Version
- 2003 or older
- Platform
- Windows
I want to modify an SI units extraction function that uses RegEx to include other units apart from m (METER).
How can I incorporate a case-sensitive list of units into the Pattern? The list is A, mol, g, cd, K, m, s, rad, sR, Hz, N, Pa, J, W, C, V, F, O, S, Wb, T, H, °C, lm, lx, Bq, Gy, Sv, kat.
I want to add the above list to incorporate the listed codes alongside < ?m > in the pattern with (\d+).?(\d*)\s*(?:da|[yzafpnµmcdhkMGTPEZY]) as common across the units.
The function:
How can I incorporate a case-sensitive list of units into the Pattern? The list is A, mol, g, cd, K, m, s, rad, sR, Hz, N, Pa, J, W, C, V, F, O, S, Wb, T, H, °C, lm, lx, Bq, Gy, Sv, kat.
I want to add the above list to incorporate the listed codes alongside < ?m > in the pattern with (\d+).?(\d*)\s*(?:da|[yzafpnµmcdhkMGTPEZY]) as common across the units.
The function:
VBA Code:
Public Function Find(x As String)
Dim oRegex As Object
If oRegex Is Nothing Then
Set oRegex = CreateObject("VBScript.RegExp")
oRegex.Global = True
oRegex.Pattern = "(\d+).?(\d*)\s*(?:da|[yzafpnµmcdhkMGTPEZY])?m"
' A, mol, g, cd, K, m, s, rad, sR, Hz, N, Pa, J, W, C, V, F, O, S, Wb, T, H, °C, lm, lx, Bq, Gy, Sv, kat
End If
Find = Empty
If oRegex.Test(x) Then Find = oRegex.Execute(x).Item(0).Value
End Function