Use regexp to find and replace with field

D

dan

I'm trying to find any numbers in a document that look like: 1.3,
3.2.1, 5.1.2.3, etc or the text 'Article 10' and replace them with a
REF field that links to the correct paragraph. I've got the linking
code working great, but I'm having trouble getting either the built in
Find or the RegExp to work correctly.

I first tried using the regex pattern
(\d{1,}\.\d{1,}(\.\d{1,}){0,})|(Article.\d{1,}
That worked really well, but when I tried to loop through the matches
as soon as I replace a number with a field the next match would be in
the wrong position. I tried a
Do While RegEx.Execute(ActiveDocument.Range.Text) to insert the fields
as it went, ala Selection.Find.Execute(), but that just threw error
messages.

I just tried a wildcard search, but I can't seem to get that to work
correctly either.
[0-9]{1,2}.[0-9]{1,2} finds most of them, but has trouble with 3.2.1

Any thoughts out there?
 
D

dan

This wildcard string works fairly well, but it also matches "1994".
[0-9]{1,2}[.0-9]{1,}
 
D

dan

I've got a pretty good system now, I use a RegEx.Test to filter out
what Find comes back with. If anybody has any other ideas, please let
me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top