Wildcard problem with ordinals

D

Dave Logan

Is there any way to do a wildcard search that strips out ordinals from dates (e.g. "19th September 2007" -> "19 September 2007", "March 21st, 2007" -> "March 21, 2007") but does *not* strip out ordinals from anything that is not a date (e.g. leaves "19th century" alone)?

I was using the search string:
<([1-9]{1,})([a-z]{2})>
and replace string
"\1"
until I discovered it was stripping the ordinal from things like 19th century, which I don't want it to do.

Dave
 
G

Graham Mayor

Not a single search with so many variables.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dave Logan

Is it possible with two searches? :)

Dave

| Not a single search with so many variables.
|
| --
| <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
| Graham Mayor - Word MVP
|
| My web site www.gmayor.com
|
| <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
|
| Dave Logan wrote:
| > Is there any way to do a wildcard search that strips out ordinals
| > from dates (e.g. "19th September 2007" -> "19 September 2007", "March
| > 21st, 2007" -> "March 21, 2007") but does *not* strip out ordinals
| > from anything that is not a date (e.g. leaves "19th century" alone)?
| >
| > I was using the search string:
| > <([1-9]{1,})([a-z]{2})>
| > and replace string
| > "\1"
| > until I discovered it was stripping the ordinal from things like 19th
| > century, which I don't want it to do.
| >
| > Dave
|
|
 
G

Graham Mayor

The following macro http://www.gmayor.com/installing_macro.htm should remove
all date ordinals using common UK or US date patterns without affecting
non-date ordinals

Sub RemoveDateOrdinals()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Jan)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Feb)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Mar)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Apr)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}May)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Jun)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Jul)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Aug)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Sep)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Oct)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Nov)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}Dec)", _
"([0-9]{1,2})[dhnrst]{2}([ ,]{1,2}[0-9]{2,4})")
vReplText = "\1\2"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText
.Execute replace:=wdReplaceAll
Next i
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Dave said:
Is it possible with two searches? :)

Dave

Graham Mayor said:
Not a single search with so many variables.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Dave said:
Is there any way to do a wildcard search that strips out ordinals
from dates (e.g. "19th September 2007" -> "19 September 2007",
"March 21st, 2007" -> "March 21, 2007") but does *not* strip out
ordinals from anything that is not a date (e.g. leaves "19th
century" alone)?

I was using the search string:
<([1-9]{1,})([a-z]{2})>
and replace string
"\1"
until I discovered it was stripping the ordinal from things like
19th century, which I don't want it to do.

Dave
 

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