[TxMt] regex question

Paul McCann paul.mccann at adelaide.edu.au
Wed Feb 22 13:32:36 UTC 2006


Hi Oliver,

> I'm trying to run a perl search/replace command via a 'bundle  
> command'. I've entered the following into the 'Edit Command' box:
>
> perl -pe '
> 	s/^([A-Z]+.*[A-Z]*\s*)\n(\(.+\))\n(.+)$/\n\n\t\t\t\t$1\n\t\t\t$2\n 
> \n$3/g;
> '
>
> I've set the input to 'Entire Document' and the output to 'Create  
> New Document'.

The problem there is that the text won't be matching. You need to  
indicate to perl that you want a multiline match to occur (ie,  that  
the regular expression should apply to all of the text in the  
document, not just one line at a time). This is done by using the "m"  
qualifier, as in

> perl -pe 's/^([A-Z]+.*[A-Z]*\s*)\n(\(.+\))\n(.+)$/\n\n\t\t\t\t$1\n\t 
> \t\t$2\n\n$3/mg;'

But written this way perl is just seeing the first line of the  
document; in order for it to see a paragraph at a time (where a  
paragraph is delimited by a blank line) you can use the flag  
"-000" (three zeroes):

> perl -000 -pe 's/^([A-Z]+.*[A-Z]*\s*)\n(\(.+\))\n(.+)$/\n\n\t\t\t\t 
> $1\n\t\t\t$2\n\n$3/mg;'

This gets you pretty close to what you're seeking, and I imagine you  
can tweak it to get it exactly right:

=======================================================================


				OLIVER
			(I want to tell you)

I've got things to say.
Dr. Robert

=======================================================================

Good luck,
Paul




More information about the textmate mailing list