About string.gsub

Hi , All 

I want to change (-3) to (0-3) , so I use the below code 

wordString = string.gsub(wordString, “^%%(-$”, “(0-”)  – ^ start , $ end 

But nothing happened. 

How to write the pattern ?

First off, use http://regexr.com/ to find the expression you need.

Secondly, take a look at the documentation and do some googling. The answer to your question is almost certainly on stackoverflow.com already.

are you just trying to replace “(” with “(0”?  with lua’s pattern syntax you’ll need to escape the parenthesis:

local source = "(-3)" local result = source:gsub( "%(", "%(0" ) print(result) --\> "(0-3)"

Thanks , I am trying to replace “(-” with “(0-” , so it’s a string , so I am using ^$ to mark the Substring pattern .

First off, use http://regexr.com/ to find the expression you need.

Secondly, take a look at the documentation and do some googling. The answer to your question is almost certainly on stackoverflow.com already.

are you just trying to replace “(” with “(0”?  with lua’s pattern syntax you’ll need to escape the parenthesis:

local source = "(-3)" local result = source:gsub( "%(", "%(0" ) print(result) --\> "(0-3)"

Thanks , I am trying to replace “(-” with “(0-” , so it’s a string , so I am using ^$ to mark the Substring pattern .