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

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -