Currency Regular Expression

前端 未结 3 1526
执念已碎
执念已碎 2020-12-06 08:13

I think I created a working regular expression for what I need. Just wondering if anyone can break it or see a shorter way to write it.

The regular expression shoul

3条回答
  •  死守一世寂寞
    2020-12-06 09:04

    Given your examples, the following regular expression will work:

    /^(\$?(?(?=\()(\())\d+(?:,\d+)?(?:\.\d+)?(?(2)\)))$/gm
    

    (note: flags and delimiters are language dependent)

    This regex sets an unnecessary backreference merely to save regex-length. You can ignore the second backreference. If this is intolerable the expression will become quite a bit longer.

    Have a look here: http://regex101.com/r/fH3lV1

提交回复
热议问题