#1
|
|||
|
|||
Find and replace numbers (up to three digits)
I have a number of citations devoid of a title, but cited only as 'yearbook 1906, p. 122' or something like that. I would need to match these citations with the actual title of the contribution.
Now, I have the titles and the extent of the contributions: I know, for example, that one specific contribution goes from page 2 to page 136. How can I replace all of the instances citing 'Yearbook 1906, p. [2 to 136]' match? I have quite a few of those, so ideally I would not like to do it manually. I know that traditional regexes do not deal well with this sort of problems. There exist solutions like this one: http://gamon.webfactional.com/regexn...angegenerator/ However, I am wondering if something can be attained within Word / Excel. Any help would be much appreciated! |
#2
|
|||
|
|||
Do the citations exist inside of a Word document? (You mention Excel, so it's not clear.) If so, we can probably come up with a wildcard find/replace solution. Perhaps you can give a precise sample of the text you want to change?
|
#3
|
|||
|
|||
They ultimately be stored in an Excel column, but of course that can be easily pasted into Word, so either that is perfectly fine. Word seems easier to work with in this regard, so let us assume that is the scenario.
A sample text to be a citation of a contribution spanning from page 2 to 137 in a given Yearbook. A text could be replaced could be either Code:
yearbook 1906, p. 24 Code:
yearbook 1906, p. 122 Code:
Author1, ArticleTitle1, YB 1906, p. 2-137 Thanks! |
#4
|
|||
|
|||
With VBA, you can probably simply find and replace with wildcards, rather than use the <Microsoft VBScript Regular Expressions 5.5> library. Although you could use that too. The advantage of regex, in my experience, is that it allows you to identify substrings of zero or more instances, whereas Word's wildcards do not.
For the example you give, you can do something like this with Wildcards Code:
Sub find_replace_yearbook() Dim d As Document: Set d = ActiveDocument Dim r As Range: Set r = d.Content Dim Author1 As String, ArticleTitle1 As String Author1 = "NameOfAuthor" ArticleTitle1 = "NameOfArticle" r.Find.ClearFormatting r.Find.Replacement.ClearFormatting r.Find.Text = "yearbook ([0-9]{4}, p. )[0-9]{1,}" r.Find.MatchWildcards = True r.Find.Replacement.Text = Author1 + ", " + ArticleTitle1 + ", YB \1" + "2-137" r.Find.Execute Replace:=wdReplaceAll End Sub |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and Replace - How to insert brackets around all numbers in a doc | Natedogg | Word | 2 | 05-21-2015 07:16 AM |
Find and replace BETWEEN numbers | WordUser2015 | Word | 4 | 12-19-2014 02:09 PM |
find and replace consecutive numbers | kpl_39 | Word | 1 | 06-07-2013 05:04 AM |
Find & Replace formula for numbers? | Griff | Word | 4 | 04-18-2011 02:47 AM |
Find and replace page numbers in body of text | tollanarama | Word | 3 | 02-13-2011 06:00 AM |