There is such a regular season.

(^[1-9]*)([0-9]?)(.{1}?)([0-9]{1,})\$?$ 

It must calculate the numbers and at the end of the dollar sign, which may not be.

She has one problem, after the dollar sign, if you write the numbers, she takes the same result.

Tell me how to solve this problem?

Here is a link to check.

It would be necessary for the regulars to take rows of such types.

 4564 45689$ 4564.4564 4564846.456$ 

And there are none.

 456415$45646 
  • Nothing is clear. Where is the desired result? - Qwertiy
  • @Qwertiy Changed the question. - Raz Galstyan
  • ^[1-9][0-9]*(?:\.[0-9]+)?\$?$ ? Demo . - Wiktor Stribiżew 2:19 pm
  • @ WiktorStribiżew super, thank you. - Raz Galstyan
  • @StrangerintheQ Test this line 000.000$ - Raz Galstyan

2 answers 2

you can use

 ^[1-9][0-9]*(?:\.[0-9]+)?\$?$ 

Details:

  • ^ - beginning of line
  • [1-9][0-9]* - a digit from 1 to 9, and after it 0 or more any digits
  • (?:\.[0-9]+)? - one or zero point repeats and 1 or more digits
  • \$? - one or zero dollar signs
  • $ - end of line.

    /^\d*\.?\d+\$?$/

    ^ = at the beginning of a line

    \d* = any number of digits (including 0)

    \. = point

    ? = may be absent

    \$ = dollar symbol

    $ = at the end of the line

     test(".01$"); test("t1est"); test("230.01"); test("foo"); test("bar"); test("3049.58$"); test("bar"); test("534.534$23"); test("123"); test("123."); function test(v){ console.log(v, v.match(/^\d*\.?\d+\$?$/)?true:false) } 

    • There is a problem. here it does not take 123 - Raz Galstyan
    • @RazGalstyan has refined - Stranger in the Q
    • Another minus. Here it takes 230. .. - Raz Galstyan
    • @RazGalstyan and this is incorrect? I specifically did so =) - Stranger in the Q
    • @RazGalstyan replaced * with + - Stranger in the Q