I want to remove spaces from a list of phone numbers. The phone numbers are in the following format: "+33 x xx xx xx xx" most of the time (quotes included). Spaces can be placed differently.

In notepad++, my "Find what:" field looks like this, and effectively matches every phone number encountered: "\Q+\E[0-9 ]+". But I don't understand how to remove a part of it (the spaces).

I thought about doing it in two steps: first selecting the results of a search with the matching pattern above, and then doing a replacement with the "In selection" checkbox ticked, but I can't find how to select all search results at once.

  • Does the text contain anything other than the phone numbers? Is searching for " " and replacing it with "" not an option? – Excellll Apr 14 '14 at 17:44

The 'simple' way is to use capture groups for each group of numbers. For a fixed format, that works well. Find:

"\+33 ([0-9]) ([0-9]{2}) ([0-9]{2}) ([0-9]{2}) ([0-9]{2})"

And replace with:


The other way is a bit more flexible, but at the same time, can be a bit confusing, since it uses the \G anchor which is not so common, with the \K anchor, which might be even less common:


(There is a space at the end) And replace with nothing.

regex101 demo

(?:          # Begin group
  "\+33      # Match "+33
|            # OR
  (?!^)\G    # At the end of the previous match (and exclude start of lines)
)            # End group
[^\s"]*      # Any non-space or quote characters
\K           # Reset the match
             # Match a space

Both \G and \K aren't available on some earlier versions of Notepad++. I don't remember exactly when they were introduced, but they work on v6.5.2.

  • Thanks, it works! But i don't understand some things: what is the point of creating a group? And what's the difference between (?: and (: ? Also, I don't understand the role of \G. – Cutter Apr 14 '14 at 18:10
  • @Cutter It will be too long to explain in a comment, but here are potentially useful links: \G and (?: ... ) – Jerry Apr 14 '14 at 18:19

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.