-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.

Lestat
  • 10,045
  • 5
  • 38
  • 70
michael01angelo
  • 113
  • 3
  • 8

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
  • 64,240
  • 8
  • 67
  • 88