Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl regex to find any number that is a multiple of 5

Tags:

regex

perl

Perl regex to find any numbers that is multiple of 5.

I tried using =~ /[5]+/ but it is finding only numbers which contains 5, but not multiple of 5.

And also to find string whose length is multiple of 5.

like image 857
user2310094 Avatar asked Dec 01 '22 21:12

user2310094


1 Answers

Numbers that are multiple of 5 either end with 5 or 0.

Try using /^-?\d*[05]$/, which means:

  • ^ start of string (saflknfvs34535 won't work).
  • -? A minus sign or not (if you only want positive numbers, don't put that).
  • \d* numbers, any numbers.
  • [05] 0 or 5.
  • $ end of string (324655sefgsfgsfg wont' work).
like image 160
SteeveDroz Avatar answered Dec 04 '22 22:12

SteeveDroz