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.
Best Answer
The 'simple' way is to use capture groups for each group of numbers. For a fixed format, that works well. Find:
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
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.