0

I have a question about regular expressions. I'm using VS Code and trying to search and replace € (price).

I have a JSON file and in that file a have price like this: "price": 120.000 € a trying to remove € so everything should look like this: "price": 120.000 Please help, thank you all.

Cid
  • 14,968
  • 4
  • 30
  • 45
jomskris
  • 293
  • 6
  • 17
  • 2
    You mean directly in the editor or using code? If by code, what language are you using? – Cid Jan 15 '19 at 10:44
  • We are here to help but have you tried anything? – revo Jan 15 '19 at 10:50
  • I repeat comment from Cid. Which language do you use ? C++, VB.Net C#, F#, Python, Node.js ? You say that you have tried. Ok, but can you give the code you have tried ? That can help us to help you :-) – schlebe Jan 15 '19 at 11:24
  • Hello, i just want to replace in json file, directly in the editor. I try to use search and replace but I also have a content and inside content is also some prices with €. When I use search and replace, it replace all € in file but I only wants replace in "price":"120.000 €" to "price":"120.000" . I tried somethng like this:^[^/\n](?:/[^/\n]+)*€ – jomskris Jan 15 '19 at 11:29
  • Considering [this](https://stackoverflow.com/a/42184299/8398549), this is JavaScript based. – Cid Jan 15 '19 at 11:47
  • @jomskris can you [edit](https://stackoverflow.com/posts/54197246/edit) your question and add your RegEx attempts instead of directly in comment? – Cid Jan 15 '19 at 11:49
  • `"price": 120.000 €` is not JSON. Are you sure about the format? – Álvaro González Jan 19 '19 at 12:51

1 Answers1

3

("price"\s?:\s?"(?:\d+\.?)+)(\s?€)" to be replaced by $1"

$1 is the first captured group. In that RegEx, this is : ("price"\s?:\s?"(?:\d+\.?)+)

  • 1st Capturing Group ("price"\s?:\s?"(?:\d+\.?)+) :

-> "price" matches the characters "price" literally (case sensitive)

-> \s matches any whitespace character (equal to [\r\n\t\f\v ])

--> ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

-> : matches the character : literally (case sensitive)

-> \s matches any whitespace character (equal to [\r\n\t\f\v ])

--> ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

-> " matches the character " literally (case sensitive)

  • Non-capturing group (?:\d+\.?)+

-> + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

--> \d+ matches a digit (equal to [0-9])

--> \.? matches the character . literally (case sensitive)

  • 2nd Capturing Group (\s?€)

-> \s matches any whitespace character (equal to [\r\n\t\f\v ])

--> ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

-> matches the character literally (case sensitive)

-> " matches the character " literally (case sensitive)

This will be replaced by $1" which is the first captured group followed by "

Test it yourself

Cid
  • 14,968
  • 4
  • 30
  • 45