At 15:28 15/12/2008 -0500, Mitchel Cohen wrote:
In an essay I wrote, I have all phrases I want to appear as italics between two codes. For example, <MI>words to appear in italic<D> . The words to be italicized are different throughout the essay. How do I do a Search and Replace for different strings of words, but all of them between <MI> and <D>?

Do you really want to replace the strings with anything, or just to set them italic? You need a regular expression here, so start by going to Edit | Find & Replace..., clicking More Options, and ticking "Regular expressions".

A first try would be to put something like <MI>.+<D> in the "Search for" box and click Find All. The .+ part matches one or more characters between your codes. The problem with this is that using the plus sign makes the pattern match as much text as possible within any paragraph. This means that if you have more than one phrase in the same paragraph, all intervening text will also be selected - which you don't want.

Where you go next probably depends on the details of your text. Do you have any other instances of, say, the less-than sign? If not, you could force the intervening pattern to match anything that didn't include this symbol, using <MI>[^<]+<D> instead. Clicking Find All should select all your phrases, and you can change every instance to italics in one go at Format | Character... | Font or by using Ctrl+I. This will italicise the codes as well as the phrases, but this may not matter as it may well be that you intend to delete the codes after they have done their work. In any case, it would be easy to set them back to roman by searching for the codes themselves afterwards.

If you do have other less-than signs in your text, you may need to carry out a multi-stage process instead, perhaps changing these to another character temporarily, or else - and probably more easily - changing the very codes you are searching for to something else first. Suppose, for instance, that there are no hash marks in your text. You could replace your codes by # or ## or perhaps #1 and #2 before you do the real Find. After you have found and modified the phrases, you can easily change back anything you needed to change.

Note in particular that you cannot search with regular expressions across a paragraph break, so you will not be able to handle a situation with an <MI> in one paragraph and the corresponding <D> in another. Your only solution would be to handle this occurrence manually or else to close and reopen each phrase with an extra <D> at the end of each paragraph and an extra <MI> at the start of each subsequent one. Another solution may be to change such paragraph breaks to line breaks, as you can match a string across a line break.

I trust this helps.

Brian Barker


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to