string - Regex Replace Zero In Some Instances -



string - Regex Replace Zero In Some Instances -

i trying write regex statement replace 0 if next conditions true

example string:

0,10,9a,0,0,20,0ld,0

change zeros t0

if 0 has 1-9 in front end not alter it if first character or lastly character 0 alter t0 if 0 has letters after 0 alter t0 same letters after before

the string above can in order , should business relationship possible alter in delims (,)

so string above should be:

t0,10,9a,t0,t0,20,t0ld,t0

this have far:

0(?=[a-z]|[1-9])|0

this get

t0,1t0,9a,t0,t0,2t0,t0ld,t0

the problem 10,20,30,40,50,60,70,80,90 beingness replaced should not.

you utilize negative lookbehind this.

(?<![1-9])0

or going off of current pattern.

(?<![1-9])0(?=[a-z1-9]?)

live demo

regex string replace

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -