regex JS question(JavaScript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

regex JS question(JavaScript)

How can I match all of a character as long as it's at the end of the value? Like Let's say I have this number I want it to only match 0s at the end of the number 167069000 It should only match the 3 zeros at the end.

23rd Sep 2018, 7:47 AM
Daniel Cooper
Daniel Cooper - avatar
8 Answers
+ 5
Calviղ The number of zeros at the end is not known though. I think this is for the factorial zeros challenge. Also, your pattern will match three zeros anywhere in the input string, not at the end. And it will include any number of random other numbers before the three zeros. This is not correct, sorry.
23rd Sep 2018, 8:28 AM
Anna
Anna - avatar
+ 4
Something like /[0]+$/ should do
23rd Sep 2018, 7:57 AM
Anna
Anna - avatar
+ 4
the two commonly used regex patterns are ^ to mark start of regex $ to mark end of regex so in calvin s answer I ll just add a $ in the end to make it safer as also explained by Anna so with /\d+0{3}/ this will also select 123000123 yes but with /\d+0{3}$/ it ll meet your specification 123000123 nope 123000 yes
23rd Sep 2018, 10:17 AM
Morpheus
Morpheus - avatar
+ 4
hi Daniel Cooper, An awesome Beginners 16 vid tutorial series byThe Net Ninja on RegEx https://www.youtube.com/watch?v=r6I-Ahc0HB4&list=PL4cUxeGkcC9g6m_6Sld9Q4jzqdqHd2HiD In the end you d know a lot about regex and also a demo on how to make a simple yet awesome form with client side validation using regex. videos are short and concise, give it a try.
23rd Sep 2018, 5:35 PM
Morpheus
Morpheus - avatar
+ 3
/[1-9](0+)\b/
23rd Sep 2018, 2:49 PM
Микола Федосєєв
Микола Федосєєв - avatar
+ 2
Morpheus Thanks. I'll make sure to watch it.
23rd Sep 2018, 7:50 PM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Exactly like this /\d+0{3}/ will do
23rd Sep 2018, 8:23 AM
Calviղ
Calviղ - avatar
+ 1
Anna is right. It's for the challenge. I'm awful at regular expressions so I decided to try out the challenge hoping to learn more about them. Also trying to learn about for loops. Lol
23rd Sep 2018, 5:28 PM
Daniel Cooper
Daniel Cooper - avatar