regex - Java regular expressions starts and ends with and contains -


i have file need use regex replace specific character. have strings of following format:

1234 4215 "aaa.bbb" 5215 1524 

and need replace periods colons. know these periods contained within quotation marks, need regex finds substring starts '"', ends '"', , contains "." , replace "." ":". shed light?

you can use:

str = str.replaceall("\\.(?!(([^"]*"){2})*[^"]*$)", ":"); 

regex demo

this regex find dots if inside double quotes using lookahead make sure there not number of quotes after dot.


Comments