+ 1

new regex question

since my old question seemed to confuse a few of you(I'm terrible at wording things lol), here's a new one I need a regular expression that will match any amount of zeros at the end of a number yes, this is for the challenge An example: Number: 6768097 Trailing Zeros: 0 Number: 267700 Trailing Zeros: 2 number: 577880 Trailing Zeros: 1 You can send your full code, as I already have a code that produces the number that will be tested Actually, I'll just include my code. https://code.sololearn.com/Wm0CPovm9N4L/?ref=app I saved it after experimenting a bit, so if you remove the zeros from the output it should work.

23rd Sep 2018, 8:04 PM
Daniel Cooper
Daniel Cooper - avatar
4 Answers
+ 2
To match everything before the zeroes, you can express it like ([0-9]+[1-9]) Which means, a number, but at the end a digit that's not 0. Then you match all the zeroes after. We also need to consider the case when the number is all zeroes. The full regex then is: ([0-9]+[1-9])?(0*) And in group 2 you have the trailing zeroes. EDIT: Though, looking at Anna's answer on the last post, /0+$/ or /0*$/ is perfect if you know that the number is at the end of the line. Nothing wrong with that!
23rd Sep 2018, 8:25 PM
Schindlabua
Schindlabua - avatar
+ 1
Can I have an example of that in my code Schindlabua?
24th Sep 2018, 12:40 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Also, the number of zeros at the end is NOT known The program takes all of the digits in the array and multiplies them. I want it to count the trailing zeros and display them. But i'm terrible at regular expressions xD
24th Sep 2018, 12:42 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Jay Matthews Well what's a good way to achieve this?
24th Sep 2018, 1:06 AM
Daniel Cooper
Daniel Cooper - avatar