user3569267
user3569267

Reputation: 1125

How to use regex to replace all semicolons inside double quoted strings by spaces?

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

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

You may use the below regex..

<cfset newline=rereplace(line,';(?!(?:\"[^\"]*\"|[^\"])*$)',' ','all')>

Upvotes: 1

Related Questions