Changing every other instance of <B> in a file

Bob Kline bkline at rksystems.com
Tue Mar 27 15:57:04 EST 2001


On Tue, 27 Mar 2001, Lars Klæboe wrote:

> On Tue, 27 Mar 2001 05:56:26 -0800, "Emile van Sebille" <emile at fenx.com>
> wrote:
> >Here's one way (although I'm interested to see how re might do this):
> 
> [--- interresting code ---]
> 
> This is another (fancier ;)) implementation of the solution I've
> been working on, but I still refuse to believe that the script has
> to be this elaborate/big. *twisting my tired gray matter*

In the spirit of using the best tool for each job, why not use lex for
this?

%s GOT_B
%%
<GOT_B>\<B\>    { printf("</B>"); BEGIN(0); }
\<B\>           { printf("<B>"); BEGIN(GOT_B); }
%%
main()          { yylex(); }
yywrap()        { return 1; }

-- 
Bob Kline
mailto:bkline at rksystems.com
http://www.rksystems.com





More information about the Python-list mailing list