[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature request: plain option for gsub
- From: Petite Abeille <petite.abeille@...>
- Date: Fri, 22 Aug 2014 00:17:09 +0200
On Aug 22, 2014, at 12:02 AM, Sean Conner <sean@conman.org> wrote:
> Yes, it has a dependency on LPeg.
Yes, it does indeed :P
function escape( s ) return ( s:gsub( '%p', '%%%1' ) ) end
function replace( s, this, that ) return ( s:gsub( escape( this ), escape( that ) ) ) end
print( replace( 'target string', 'get', 'ball' ) )
print( replace( '100% efficiency with 20% effort', '%', ' per cent' ) )
print( replace( 'ababababababa', 'ababa', 'xx' ) )
> tarball string
> 100 per cent efficiency with 20 per cent effort
> xxbxxba