Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a period using a regular expression 1

Status
Not open for further replies.

Strobeman

Programmer
May 16, 2003
40
AU
Hi Guys,
Hopefully someone can help me with this tricky one.
I am currently maintaining some VBA code that formats a word document. One of the things it does is search for the people mentioned on each page and put the name of the last person mentioned on the page in the footer.

An example would be MR BLOGGS:

The current regex being used is "[A-Z -']{1,}:"
This also caters for MR O'REILLY: and MR ROSS-JONES:

Now they want me to cater for MR H. HOPPER: and the other variations of salutations and you would think it would be as simple as "[A-Z -'\.]{1,}:" but for some reason it does not work.

Here are some of the other variations I have tried and I admit, some of them are pretty poor:
"[A-Z]{1,}\.?[A-Z '-]{1,}:"
"[A-Z '-\.]{1,}:"
"[A-Z '-.]{1,}:"
"[A-Z '-]{1,}\.?[A-Z '-]{1,}:"
"[A-Z]?\.?[A-Z '-]{1,}:"
"[A-Z ]{1,}\.?[A-Z '-]{1,}:"
"[A-Z \x27\x2D\x2E]{1,}:"
"[A-Z -'`]{1,}:"
"[A-Z -'`]{1,}\x2e?[A-Z -'`]{1,}:"
"[A-Z\40\55\47]{1,}:"
"[A-Z(\40)(\55(\47)]{1,}:"
"[A-Z ]{4,}\.?[A-Z -']{1,}:"

Anyway, none of these work and so I really hope someone out there has a better idea.
Many thanks :)
 
Try
Code:
"[A-Z -'\\.]{1,}:"
you may find that the first backslash is being removed when the quoting is interpolated.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
And this ?
Code:
"[- .'A-Z]{1,}:"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Strobeman,

If you use a Find Expression like:
<[A-Z.]{1,} [A-Z-\'’]{1,}>
and format the found text with a unique character style, you can then use a STYLEREF field to pull the name of the last person mentioned on the page into the footer.

For example, you might define a Character Style named 'FooterCitation', which does nothing more than apply a 'small caps' attribute to whatever happens to be the underlying paragraph font. Since you're only working with found upper-case characters, this is of no consequence. Then you could use a macro like:
Code:
Sub MarkRefs()
With Selection.Find
  .ClearFormatting
  .Text = "<[A-Z.]{1,} [A-Z-\'’]{1,}>"
  .Replacement.Text = "^&"
  .Replacement.ClearFormatting
  .Replacement.Style = ActiveDocument.Styles("FooterCitation")
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchCase = False
  .MatchWholeWord = False
  .MatchAllWordForms = False
  .MatchSoundsLike = False
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
End Sub
to apply the Style to the names.

Finally, insert a STYLEREF field into the footer coded as:
{STYLEREF FooterCitation \l}

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top