Delete delimiter from columns csv regex

Viewed 30

Is there any way to detect only the double quotes that are not surrounded by semi-column or if it is at the end of the line ? Example:

test1;"col11 " col12";"col3" 
test1;"col11" col12";"col3" 
test1;"col11 "col12";"col3" 
test1;"col11"col12";"col3"

Output :

test1;"col11  col12";"col3"
test1;"col11 col12";"col3"
test1;"col11 col12";"col3"
test1;"col11col12";"col3"

I used this regex : \b(?!;"|";|"$|"\n)" but the \b excludes the double quote preceded by a space.

1 Answers

You can use

(?<=[^;\r\n])"(?=[^;\r\n])

See the regex demo.

Details

  • (?<=[^;\r\n]) - immediately on the left, there should be a char other than ;, CR and LF
  • " - a double quote
  • (?=[^;\r\n]) - immediately on the right, there should be a char other than ;, CR and LF.
Related