Replace tab spaces only inside quotations.
-
Hi all,
I am quite stuck on this
I have the following as an example
Bit1 “Bit2 Bit3 Bit4 Bit5”
I want to replace the tab in between Bit2, Bit3, Bit4 etc with a space, but leave the tab after Bit1, in short replace all tab chars inside quotations with a space.
How can this be done, the file I have as over 40,000 lines like the example above so doing it by hand is not possible.
Regards,
-
Try this:
From the main menu, select Search | Replace…; then fill in:
Find what:
\t(?=[^\r\n"]*+"[^\r\n"]*+[\r\n])
Replace with: (a single space)
Search Mode: Regular expressionthen click Replace All.
This assumes that each line in your text either has no double quote marks or has two double quote marks. If there are other cases (such as lines with two quoted strings, or quoted strings that span lines) this will not work.
-
@Coises That worked, thank you!
-
Hello, @uhax-the-grey, @coises and All,
Your solution, @coises, seems to work only if :
-
A single
"......"
section exists in current line -
Line-ending char(s) end(s) the current line
@uhax-the-grey, the difficulty to achive that general goal is that the ending char of a section is the SAME char than its beginning char ( the
"
character ) :-((So I propose to split the problem in
3
successive steps :-
First, we change any couple of
"
chars, of a single section, with two different control chars (\x02
and\x03
) -
Secondly, we use the generic regex mechanism, described here, to replace any
\t
character by a space char, in"............"
sections only -
Finally, we restore the two original
"
delimiters for each section
This method leads to the
3
successive regex S/R below :SEARCH
(?s)"(.*?)"
REPLACE
\x02\1\x03
Then :
SEARCH
(?:\x02|(?!\A)\G)(?s:(?!\x03).)*?\K\t
REPLACE
\x20
Remark : Do not forget to move the caret ( cursor ) at the very beginning of the current file, before running this second S/R !
Finally :
SEARCH
[\x02\x03]
REPLACE
"
Whatever the position of the TAB chars and the
"
deleimiters, thoughout the text contents, this method should always work properly !Best Regards,
guy038
-