[TxMt] erasing block within tags

Hans-Joerg Bibiko bibiko at eva.mpg.de
Sat Nov 11 01:22:16 UTC 2006


Quoting James Fishwick <fishwick.hmco at gmail.com>:

> I'm trying to write a snippet that will erase
>
> *everything within inclosing tags
> and
> *everything with enclosing tags including the tags themselves.
>
> So far I've got `perl -e
> 's/<\${TM_SELECTED_TEXT}>(\n|.)+?/<\/${TM_SELECTED_TEXT}>//g'`,

Try this:

Replace `perl -e  
's/<\${TM_SELECTED_TEXT}>(\n|.)+?/<\/${TM_SELECTED_TEXT}>//g'`

with this:

#!/usr/bin/perl -X
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
$tag = $ENV{'TM_SELECTED_TEXT'};
$data="";
while(<>){$data.=$_}
$data=~s/<$tag>(\n|.)+?<\/$tag>//mg;
print $data;

Some hints:
- if you are dealing with multiple lines in regexp you have to use s///m
- typo, you have s////
- \${TM_SELECTED_TEXT} doesn't work for me
- if you call perl via -e etc. it will parse your STDIN line by line

Cheers,

Hans

BTW a good idea ;)

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the textmate mailing list