1

I have multiple lines like this:

{
"source": "Source A",
"target": "Source B",
"idTarget": "3,345",
"strength": "0.5",
"value": "633.5138"
}
{
"source": "Source C",
"target": "Source D",
"idTarget": "1,253",
"strength": "0.7",
"value": "5465.238"
}

I want to remove the . (dot) in line that has the word value, but not on other lines. So it would look something like this:

{
"source": "Source A",
"target": "Source B",
"idTarget": "3,345",
"strength": "0.5",
"value": "6335138"
}
{
"source": "Source C",
"target": "Source D",
"idTarget": "1,253",
"strength": "0.7",
"value": "5465238"
}

Any way to do this?

2
  • Ctrl+H
  • Find what: ^"value":[^.]+\K\.
  • Replace with: LEAVE EMPTY
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

^           : begining of line
  "value":  : literally
  [^.]+     : 1 or more not dot
  \K        : forget all we have seen until this position
  .         : a dot

Result for given example:

{
"source": "Source A",
"target": "Source B",
"idTarget": "3,345",
"strength": "0.5",
"value": "6335138"
}
{
"source": "Source C",
"target": "Source D",
"idTarget": "1,253",
"strength": "0.7",
"value": "5465238"
}
  • Thank you for \K: I've not come across it before, as I usually use sed, which doesn't support it (even with -r option for extended RE). – AFH Nov 16 '17 at 14:14
  • 1
    You're welcome, glad it helps. – Toto Nov 16 '17 at 15:41
1

Assuming your numbers are always formatted like 123.1234, you can use a regular expression to achieve this:

Find what: "value": "([0-9]+)\.([0-9]+)"
Replace with: "value": "$1$2"
Search mode: Regular expression

This search expression will find strings that match "value": "<numbers>.<numbers>" and put the numbers that it found in a "capture group", denoted with the round brackets. Both groups ($1, $2) are then added back into the replaced text without the dot.

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.