PDA

View Full Version : Finding past perfect



vkhu
09-01-2017, 04:26 AM
I'm working on a macro that would find any form of "had V-ed" and replace them with a Vietnamese equivalence. The macro itself is just a simple find & replace command, tested with some other queries and worked like a charm.

The problem is I can never seem to figure out an expression to track the past perfect form. Currently, I'm using the following wildcard expression:

had (<[A-z]{1,}ed>)
It never found anything. Did I make a mistake somewhere?

gmaxey
09-01-2017, 04:42 AM
What specific word or words are you trying to find?

vkhu
09-01-2017, 04:52 AM
Anything that ends with an "ed" and is preceded by the word "had" (ie. "had joked", "had showered", "had paused",...)

gmaxey
09-01-2017, 06:01 AM
Sub ScratcMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 9/1/2017
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "had *ed>"
.MatchWildcards = True
While .Execute
oRng.Select
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub

vkhu
09-01-2017, 06:14 AM
20228
I test searched the query, and this happen. Apparently, "*" is not limited to just 1 word.

macropod
09-01-2017, 06:30 AM
I'm working on a macro that would find any form of "had V-ed" and replace them with a Vietnamese equivalence. ... The problem is I can never seem to figure out an expression to track the past perfect form.

Anything that ends with an "ed" and is preceded by the word "had" (ie. "had joked", "had showered", "had paused",...)
Do note the past perfect form can include other words between the had and the word ending in 'ed'. The Find expression in Greg's macro will find multi-word strings of any length starting with 'had' until it encounters a word ending in 'ed'. Accordingly, it will find past perfect forms that include intervening words - which is a good thing - but it's also liable to make some false matches (e.g. I once had a car that was loud. It was also fast - which is what you'd expect because it was red). If you want to limit the Finds to word pairs, try:
Find = had <[! ]@ed>