Help with a Find/Replace in Word
July 7, 2008 9:52 AM Subscribe
I’m at the end of my rope trying to figure out how to write a find/replace expression in MS Word (syntax is similar to regex)
I need to turn this:
[xv][#AuthorA:2001] text text text text text [123][#AuthorB:2000] text text text text [456-78][#AuthorC:1999]
into this:
{AuthorA:2001@xv} text text text text text {AuthorB:2000@123} text text text text {AuthorC:1999@456-78}
Searching for \[(*}\]\[#(*)\] and replacing with \{\2\@\1\} doesn’t work (the search isn’t specific enough and will match "[xy][#AuthorA:2001] text text text text [123]" which screws up the replace).
Can anyone help me figure this out? Alternately, is there any kind of expression builder that could help with this? I am very much not a programmer of any kind. THANKS!
I need to turn this:
[xv][#AuthorA:2001] text text text text text [123][#AuthorB:2000] text text text text [456-78][#AuthorC:1999]
into this:
{AuthorA:2001@xv} text text text text text {AuthorB:2000@123} text text text text {AuthorC:1999@456-78}
Searching for \[(*}\]\[#(*)\] and replacing with \{\2\@\1\} doesn’t work (the search isn’t specific enough and will match "[xy][#AuthorA:2001] text text text text [123]" which screws up the replace).
Can anyone help me figure this out? Alternately, is there any kind of expression builder that could help with this? I am very much not a programmer of any kind. THANKS!
Err...I actually tested \[(*)\]\[#(*):(*)\], but the first version should work too as long as all of your dates are 4 digits.
posted by jedicus at 10:25 AM on July 7, 2008
posted by jedicus at 10:25 AM on July 7, 2008
Find what: \[([!#]?*)\]\[#(?*)\]
Options: Use Wildcards
Replace with: {\2@\1}
posted by grouse at 10:25 AM on July 7, 2008
Options: Use Wildcards
Replace with: {\2@\1}
posted by grouse at 10:25 AM on July 7, 2008
Response by poster: You guys are the bestest!
Both search strings return the right result, but the replace strings give an error (The Replace With text contains a group number which is out of range.)
posted by agent99 at 10:48 AM on July 7, 2008
Both search strings return the right result, but the replace strings give an error (The Replace With text contains a group number which is out of range.)
posted by agent99 at 10:48 AM on July 7, 2008
I got that error, too, agent99. Originally I had \{\2:\3\@\1\}, but removing the escape slashes before the curly braces (i.e., {\2:\3\@\1}) fixed it. You may need to add them back in for your version, I'm not sure.
What version of Office are you using? I tested it using 2007.
posted by jedicus at 10:56 AM on July 7, 2008
What version of Office are you using? I tested it using 2007.
posted by jedicus at 10:56 AM on July 7, 2008
agent99, when I used your example strings, it gave me an error. I'm also using Microsoft Word 2007. What jedicus said.
posted by grouse at 11:51 AM on July 7, 2008
posted by grouse at 11:51 AM on July 7, 2008
« Older Bad haircut plus dry and damaged hair. What should... | Roadtrip in the square states. Weird attractions? Newer »
This thread is closed to new comments.
[Pages][#Author:Date]
into
{Author:Date@Pages}
Find: \[(*)\]\[#(*):([0-9]{4})\]
Replace: {\2:\3\@\1}
That should work. I successfully tested it on Word 2007.
posted by jedicus at 10:24 AM on July 7, 2008