tyija1995
Well-known Member
- Joined
- Feb 26, 2019
- Messages
- 781
- Office Version
- 365
- Platform
- Windows
Hi all,
I've tried reading up on regular expressions but I am drawing a blank as to how to extract from a string 3 consecutive digits (no more, no less).
So if I have:
[TABLE="class: grid, width: 750"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]String:[/TD]
[TD]my test 1: 123 string 23: 456 that I need to extract numbers 25 789 from.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Expected Output:[/TD]
[TD]123456789[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Logic:[/TD]
[TD]Extract only where there are 3 consecutive numbers (no more, no less)[/TD]
[/TR]
</tbody>[/TABLE]
I have wrote this but it's doing the opposite and I can't figure out how to negate it...
Used on my string provided I get:
"my test 1: string 23: that I need to extract numbers 25 from."
So the bit I have replaced essentially is the bit I want to reference, but I don't know how to.
Thanks!
I've tried reading up on regular expressions but I am drawing a blank as to how to extract from a string 3 consecutive digits (no more, no less).
So if I have:
[TABLE="class: grid, width: 750"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]String:[/TD]
[TD]my test 1: 123 string 23: 456 that I need to extract numbers 25 789 from.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Expected Output:[/TD]
[TD]123456789[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Logic:[/TD]
[TD]Extract only where there are 3 consecutive numbers (no more, no less)[/TD]
[/TR]
</tbody>[/TABLE]
I have wrote this but it's doing the opposite and I can't figure out how to negate it...
Code:
Function Extract3Digits(txt As String) As String
Dim rgx As Object
Set rgx = CreateObject("VBScript.RegExp")
With rgx
.Global = True
.Pattern = "\d{3}"
Extract3Digits = .Replace(txt, "")
End With
End Function
Used on my string provided I get:
"my test 1: string 23: that I need to extract numbers 25 from."
So the bit I have replaced essentially is the bit I want to reference, but I don't know how to.
Thanks!