[TxMt] regex question

Oliver Taylor oliver at ollieman.net
Thu Feb 23 02:23:47 UTC 2006


>     #!/usr/bin/perl
>     local $/;             # put Perl in "slurp" mode
>     $text = <>;           # read in the whole file
>     $text =~ s/^([A-Z ]+)\n(\(.+\))\n(.+)$/\n\n\t\t\t\t$1\n\t\t\t$2 
> \n\n$3/mg;
>     print $text;

Of all the solutions proposed here, this once seemed to work the  
best. Thanks for the tip about processing the entire document in one go.

I ended up with the following:

#!/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\)\d]$\n^(.*)$/\n\t\t\t\t$1\n\t\t$2\n/;
	$text =~ s/^\*\*\*//mg;
	$text =~ s/^(.*(IN:|UP:|TO:))$/\n\t\t\t\t\t\t\t\t\t\t$1\n/;
	$text =~ s/^(\w+.*(\.|\?|\!|\"|\-))$\n^\w+.*(\.|\?|\!|\"|\-)$/\n$1/mg;
	print $text;

...but it doesn't work at all. I'm guessing that it's something  
obvious that I can't see, but in case it's not an explanation of what  
I'm trying to do follows.

1. removes trailing whitespace at the end of a string (which is  
common in the format I'm importing from.
2. appends three *'s to the beginning of what I'll call well-formed  
sluglines so that step 4 doesn't apply to these are well.
3. finds a specific set of lines, a Character followed by  
Parenthetical, followed by Dialoge. And formats it.
4. finds Character followed by Dialogue when there is no  
Parenthetical, and formats it.
5. repairs the sluglines that were changed in step 2.
6. formats transitions.
7. formats regular paragraphs (this is a little funky, but it's my  
fault).

I can do all these in the Find&Replace window, but I get nothing when  
running this bundle command.

You can find a sample document to test the script on here: http:// 
ollieman.net/files/bundles/braveheart-sample-unformatted.txt
And you can find what the result should look like here: http:// 
ollieman.net/files/bundles/braveheart-sample-formatted.txt

Thanks again for all the help. This will allow we to switch full-time  
from Final Draft to TextMate. Something I'm really looking forward to.



More information about the textmate mailing list