E
E
Eugene Chefranov2020-04-26 17:28:24
Regular Expressions
Eugene Chefranov, 2020-04-26 17:28:24

How to use the regex correctly?

There is a file for several hundred lines with data (such as a cast base, one line = one entity) in this form:

A1|-375,9|16,2|24,55|4,74|-6,28
B1|-151,9|9,5|11,67|1,08|-1,56
C1|-916,54|50|62,4|12,6|-12,46
D1|-143,84|6,4|10,18|1,74|-1,48
....

I want to use a regular expression (find and replace) in the editor (Notepad ++ / Visual Code) to turn objects into json, like this:
{
    "name": 'A1',
    "h": -365.9,
    "s": 16.2,
    "a": 24.55,
    "b": 4.74,
    "c": -6.28
},
{
    "name": 'B1',
    "h": -151.9,
    "s": 9.5,
    "a": 11.67,
    "b": 1.08,
    "c": -1.56
}
...

Well, then just change the file extension to .json. Tell me regular?

5ea59a781b818692459172.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-04-26
@Chefranov

First, replace the commas in the numbers with dots.
And then
Find:

^([^|\n]+)\|([-.\d]+)\|([-.\d]+)\|([-.\d]+)\|([-.\d]+)\|([-.\d]+)

replace:
{"name":'$1', "h":$2, "s":$3, "a":$4, "b":$5, "c":$6},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question