Javascript- Regular expression -
sampletext='6501-*-5-[*]'
expected output
result='6501-%-5-[*]'
i have replace * % , leave [*] is. there might multiple occurance of both. how can in javascript. in advance.
try this:
sampletext = sampletext.replace(/\*/g, function(match, offset){ if(offset > 0) { if(sampletext[offset - 1] == '[' && sampletext[offset + 1] == ']'){ return match; } } return '%'; });
fiddle: here
Comments
Post a Comment