[TxMt] Re: Select and Replace: magic needed....

Jeff Newman bangersandmash at gmail.com
Tue Jun 16 13:58:38 UTC 2009


On 15/06/09 6:43 PM, "Nicholas Cole" <nicholas.cole at gmail.com> wrote:

> On Mon, Jun 15, 2009 at 8:01 PM, Alex Ross<tm-alex at rosiba.com> wrote:
>> How about:
>> 
>> `(.*?)'(?!s)
>> 
>> So it starts by matching `, and matches until it finds a single ' that
>> is not followed by ³s².
>> 
>> Now you can replace this with
>> 
>> \enquote{$1}
> 
> Dear Alex,
> 
> I will admit that is very, very cunning.  Unfortunately, there is one
> other convention that messes it up, which is that some (especially
> classical) possessives are in the form Socrates'.  Still, they are
> rare and that does make that regex useful!

I'm not sure how to capture this in regex, since I have not yet mastered
that particular kung-fu, but shouldn't most quoted text terminate with
punctuation, where as posessives and contractions would usually not have an
additional piece of punctuation immediately beside them? For example:

> This is `some of Jefferson's text.'

Or

> The vagabond stared and said 'the rails are the way to travel,' and then moved
along.

So for a quotation the terminating quote mark will either be preceded or
followed by punctuation (depending on whether you put your periods inside of
the quote marks or outside). A possessive such as Socrates' or a contraction
like 'I've' would normally be followed by a space or another character.

Something like this seems to work:


Find:
`(.*?)(\.|\,)'(?!s)

Replace:

\enquote{$1$2}$3

jeff






More information about the textmate mailing list