[TxMt] regex question

Dr. Drang drdrang at gmail.com
Thu Feb 23 14:14:29 UTC 2006


On Feb 23, 2006, at 1:44 AM, Oliver Taylor wrote:

>> Try this
>>
>> #!/usr/bin/perl
>> local $/;             # put Perl in "slurp" mode
>> $text = <>;           # read in the whole file
>> $text =~ s/(\s+)$//mg;
>> $text =~ s{((INT\.|EXT\.|I/E\.|int\.|ext\.|i/e\.)\s.*)$}{***$1}mg;
>> $text =~ s/^([A-Z].*[A-Z)])\n^(\(.*\))\n(.+)$/\n\t\t\t\t$1\n\t\t\t 
>> $2\n\t\t$3\n/mg;
>> $text =~ s/^([A-Z]{2,}.*[A-Z)0-9])\n(.*)$/\n\t\t\t\t$1\n\t\t$2\n/mg;
>> $text =~ s/^[*]{3}(.+)$/\n$1\n/mg;
>> $text =~ s/^(.*(IN:|UP:|TO:))$/\n\t\t\t\t\t\t\t\t\t\t$1\n/mg;
>> $text =~ s/^(\w+.*(\.|\?|\!|\"|\-))\n\w+.*(\.|\?|\!|\"|\-)$/\n$1/mg;
>> print $text;
>
> Wow, thanks Dr. Drang! That worked perfectly. I'll be releasing the  
> bundle soon, and i'll be sure to let you guys know.

In the interests of time, I didn't comment the regexes, but since  
they are so complicated you should consider using the 'x' modifier  
and commenting each chunk.

--
Dr. Drang





More information about the textmate mailing list