|
|
||
|
Philippe Lhoste wrote:What if the pattern contains characters like |^$()%.[]*+-?| ?Perhaps that:
oldString = "Sale: 10% off, plus additional 5% off if 100% insured" generatedPattern = "0%" replace = "$" pattern = string.gsub(generatedPattern, "%%", "%%%%") newString = string.gsub(oldString, pattern, replace) print(newString)
Seems to work, at least with this simplistic test...
Watch your mouth! :-P
I suggest that (not tested) :
pattern = string.gsub(generatedPattern, "(%c)", "%1") newString = string.gsub(oldString, pattern, replace)
%c represents all control characters
If it does not work, [^%w] must work because all escaped non-alphanumeric character represent the character itself
Is it possible to add a parameter to switch to a plain text replacement ...? It would be very useful ... Why should I use regular expressions when I only need plain text replacement ?
-- Philippe Lhoste -- (near) Paris -- France -- http://Phi.Lho.free.fr -- -- -- -- -- -- -- -- -- -- -- -- -- --