S
S
Sergey2021-08-02 13:25:38
JavaScript
Sergey, 2021-08-02 13:25:38

How to make a regular expression for the string 11.22-+2222.22-+333.22-+44.22?

The next line is 11.22-+2222.22-+333.22-+44.22

1) the numbers before the dot can be in the amount from 1 to 4.
2) the numbers after the dot can be in the amount from 0 to 2. Accordingly, you can’t end with a dot either.
3) there can only be + or - between numbers. Two characters in a row are prohibited.
4) the whole line can only end with a number.
5) the line can contain from 1 to 4 numbers. For example (11.22 or 11.22-2222.22 or 11.22+2222.22-333.22 or 11.22-2222.22+333.22-44.22).

I get only a non-working horror in the form -

/((^\d*$)|(^\d*\.\d{0,2}$))|(?:((^(\+?|\-?)$)\d*\.\d{0,2}$)|((^(\+?|\-?)$)\d*$))?(?:((^(\+?|\-?)$)\d*\.\d{0,2}$)|((^(\+?|\-?)$)\d*$))/

Please tell me how to make this regular

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-08-02
@DaveGarrow

/^\d{1,4}(\.\d{1,2})?([+-]\d{1,4}(\.\d{1,2})?){0,3}$/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question