ruby - Replace all colon character that does not occur after specific word pattern -
for given text
pack: box five: dozen: liquor: jugs ::: :
i want replace : ; occur after words ack , zen. output expect here is
pack: box five; dozen: liquor; jugs ;;; ;
note : after ack , zen untouched whereas else replaced.
please me. able match (ack|zen):. giving me matches ack: , zen:. dont know how negate , construct regex.
note: using ruby.
you can use negative look-behind here , use gsub:
puts "pack: box five: dozen: liquor: jugs ::: :".gsub(/(?<!ack|zen):/, ";") results:
pack: box five; dozen: liquor; jugs ;;; ; you can use look-behind here because both parts of same size (3 chars).
Comments
Post a Comment