harish
harish

Reputation: 9

How to remove specific characters in notepad++ with regex?

This is data present in my .txt file

+919000009998    SMS    +919888888888
+919000009998    MMS    +91988 88888 88
+919000009998    MMS   abcd google
+919000009998    MMS    amazon

I want to convert my .txt like this

919000009998    SMS    919888888888
919000009998    MMS    919888888888
919000009998    MMS   abcd google
919000009998    MMS    amazon

removing the + symbol, and also the spaces if present in third column only if it is a number, if it is string no operation to be performed

is there any regex to do this which can I write in search and replace in notepad++?

Upvotes: 0

Views: 3639

Answers (2)

Julio
Julio

Reputation: 5308

All previous answer will perfectly work.

However, I'm just adding this just in case you need it:

If for some reason you had non-phone numbers on the third column separated by spaces (a street comes to mind for me +919000009998 MMS street foo nº 123 4º-B) you may use this regex instead (It will join number as long as the third column starts by +):

Search: ^[+](\S+\s+\S+\s++)(?:([^+][^\n]*)|[+])|\G\s*(\d+)

Replace by: \1\2\3

That will avoid joining the 3 and 4 on my previous example.

You have a demo here.

Upvotes: -1

Toto
Toto

Reputation: 91430

  • Ctrl+H
  • Find what: \+|(?<=\d)\h+(?=\d)
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

  \+            # + sign
|               # OR
  (?<=\d)       # positive lookbehind, make sure we have a digit before
  \h+           # 1 or more horizontal spaces
  (?=\d)        # positive lookahead, make sure we have a digit after

Screen capture:

enter image description here

Upvotes: -1

Related Questions