René K
René K

Reputation: 396

Remove end of line character, if another string is in the line (RegEx, Notepad++)

I have a JSON file, where I would like to remove the comma at the end of each line with the key FullName using Notepad++. I read about regular expressions and checked many forum questions without success.

{
  "Symbol": "BTC",
  "CoinName": "Bitcoin",
  "FullName": "Bitcoin (BTC)",
},
{
  "Symbol": "LTC",
  "CoinName": "Litecoin",
  "FullName": "Litecoin (LTC)",
},
{
  "Symbol": "XMR",
  "CoinName": "Monero",
  "FullName": "Monero (XMR)",
}

Upvotes: 0

Views: 212

Answers (1)

revo
revo

Reputation: 48711

Translating that requirement into a regex isn't that hard. Just follow what you say:

^(\s*"FullName".*),

and replace it with $1 (back-reference to first capturing group) or you can search for:

^\s*"FullName".*\K,

and replace it with nothing.

  • ^ means assert start of line
  • \s* any following space characters
  • .* anything up to end of line
  • \K reset match

Upvotes: 2

Related Questions