-1

I wanna learn more of regex But the complexity of the patterns makes my learning difficult.

I need to find all trailing zeros in a string. Can someone show me a pattern then explain how it works.

Daahrien
  • 10,190
  • 6
  • 39
  • 71
michael01angelo
  • 130
  • 2
  • 9

1 Answers1

1

Try /[0]+$/g

For example

"2342300".match(/[0]+$/); //["00"]

Explanation

  • [0]+ matches continous 0s
  • $ at the end matches end of the input and ensures only 0s at the end of the string is matched.
gurvinder372
  • 66,980
  • 10
  • 72
  • 94