You don't need RegEx. Identifying the numbers is not the hard part, working out what to do with them is the hard part.
I don't have time to work on this today so I will just give you some tips on how I would handle this.
The problem with spans (page ranges) is that there are understood numbers that could click over and add preceding digits. So I would prepare the trailing numbers by filling in the understood numbers before adding 2. For example
75 transforms to 77
99 transforms to 101
75-9 needs to become 75-79 before we add two to both to make them 77-81.
88-9 needs to become 88-89 then transform to 90-91 then an extra cleanup step to become 90-1
97-9 needs to become 97-99 then transform to 99-101
99-100 transforms to 101-102 and cleans up to 101-2
So the macro workflow should be:
1. Expand all 'understood' numbers to be the actual number by adding the missing digits
2. Add 2 to every number (whether in a span or not)
3. Simplify the spans where length and initial digits match
Look at the arrStr() elements in my earlier code. This gives you two strings for the spans, you can then test the Len("string") and use Left("string",1) to backfill a digit into the understood character position.
To include the spanning number patterns you actually have change this line in my original code
.Text = "[0-9]{1,4}–[0-9]{1,4}"
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
|