javascript - Look behind replace all occurrences -
i want replace occurences of .digit 0.digit.
i'm new regular expressions far understand use behind this. js not support that, i'd know if knows solution. show problem wrote following code.
str = "0.11blabla.22bla0.33bla.33" allow = "\\.\\d*" str.match(new regexp(allow,"g")) [".11", ".22", ".33", ".33"] deny = "0\\.\\d*" str.match(new regexp(deny,"g")) ["0.11", "0.33"] diffreg= new regexp("(?!"+deny+")"+allow,"g") // translates to: /(?!0\.\d*)\.\d*/g str.match(diffreg) [".11", ".22", ".33", ".33"]
obviously allow matches decimal values whereas deny matches values preceding 0. result should of course set difference between two: [".33", ".33"].
i think looking regex instead
[0]?(\.\d*)
so in code have:
intersectionreg = new regexp("[0]?("+allow+")","g")
thanks @richard, edited
Comments
Post a Comment