I need to extract a 3-digit number from text strings in an excel sheet. I've written my custom function to return a substring based on a pattern, that's fine, it works. It's the pattern that's beating me. So, examples could include:
- Lorem ipsum dolor cc123 sit amet
- Lorem ipsum dolor sit amet cc 123
- Lorem ipsum c 123, dolor sit amet
I'm no expert in regex, but usually I'd use (?<=\D)\d{3}\b That works with all the tests I've tried but VBA doesn't seem to support (?<=x). Using just \D\d{3}\b and trimming the leading char works, but offends my senses.
I'm using the standard VBscript Regular Expressions 5.5 library.
The practical background to this is that I have a large worksheet that has a comments field on each line. Policy has been that users include their cost centre somewhere in this field. It can appear anywhere in the field, it's always a three-digit number, it is always followed by a word boundary and it is always preceded by a non-number char.