What does + (?! \ D) mean in a regular expression?

I also saw it as + $.

I use

$(this).text( $(this).text().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") );

To convert 10,000 to 10,000, etc.

I think I understand everything:

  • (\ d) - find the number
  • (? = \ d {3}) - if you follow 3 numbers
  • '+' - do not stop after the first search
  • (?! \ d) - starting from the last number?
  • / g - for the whole line
  • "$ 1" - replace the number with self and comma
+5
source share
2 answers

I think you are not reading it slightly:

  • (? = \ d {3}) - if you follow 3 numbers

Note that regexp is actually:

(?=(\d{3})+

i.e. you missed the open wig. All of the following:

(\d{3})+(?!\d)

(?= ... ), - , , , .

(?!\d) , a \d (.. ) , :

  • (\d) .
  • (?=(\d{3})+(?!\d)) , , , .

"$1,", .. .

, , , !

+7

?! , -, - ,

+1

All Articles