Reputation: 1125
I need to replace all semicolos ;
in lines of a file by a space character only when the semicolon is between double quotation marks " "
.
For example the following line
'in this area the semicolon should not be replaced "however in this area it ; should be" other text "another ; text" ;....'crlf
should be modified to
'in this area the semicolon should not be replaced "however in this area it should be" other text "another text" ;....'crlf
using regular expression.
I succeeded only on replacing all text between quotation marks with nothing, i.e. to delete the double quoted text.
This is what I used in ColdFusion language:
<cfset newline=rereplace(line,'\"[^\"]*\"','','all')>
Has anyone an idea how can I use regex to replace only the semicolon character by a space when it is positioned between quotation marks?
Upvotes: 2
Views: 476
Reputation: 174706
You may use the below regex..
<cfset newline=rereplace(line,';(?!(?:\"[^\"]*\"|[^\"])*$)',' ','all')>
Upvotes: 1