Robert Klemme
1/27/2005 10:31:00 AM
"ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
news:200501271020.j0RAKGL04736@moulon.inra.fr...
> >>>>> "B" == Bil Kleb <Bil.Kleb@NASA.Gov> writes:
>
> B> gsub( /(?!\w)'(.*?)'/, '`\1\'' )
>
> (?!) is a zero-width negative look-ahead
>
>
> B> assert_equal( "isn't fool'd", "isn't fool'd".to_tex )
>
> When the regexp engine is at this position (just before ')
>
> "isn't fool'd"
>
> ^
> |
>
> * it look if it don't have a word character (\w) : this is true because
the
> first next character is '
>
> * then it look if it has ' : it's true and it match
These seem to work:
>> class String
>> def to_tex
>> gsub( /(?:\A|(?![\w']))'(.*?)'/, '`\\1\'' )
>> end
>> end
=> nil
>> "'single quotation'".to_tex
=> "`single quotation'"
>> class String
>> def to_tex
>> gsub( /'((?:[^\\']|\\.)*)'/, '`\\1\'' )
>> end
>> end
=> nil
>> "'single quotation'".to_tex
=> "`single quotation'"
But I dunno whether they fix all of your problems.
Kind regards
robert