Problem: I need to modify hundreds of rows in a .csv for an import, the import software does not like spaces in the name field (but will accept them in the description field) so I need to replace only spaces on each line up to the first "quotation mark".

Example Line:

West Side Switch 1,33,"Incl...

Would want it to look like:


I am not super familiar with working with regex so i figured this would be a good learning opportunity.


With Notepad++, here is a way to do the job, this will replace all spaces present before the first double quote:

  • Ctrl+H
  • Find what: (?:^|\G)([^"\h]*)\h
  • Replace with: $1-
  • check Wrap around
  • check Regular expression
  • Replace all


(?:         : start non capture group
  ^         : beginning of line
 |          : OR
  \G        : search from the last match position
)           : end group
(           : start group 1
  [^"\h]*   : 0 or more character that is not a quote or a horizontal space
)           : end group
\h          : horizontal space


$1          : content of group 1
-           : a dash
  • This worked perfectly, thank you for the detailed explanation. – tyrannosaurusRekt Jul 5 '18 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.