Regex 101 Exercise I9 – Count the number of matches


Regex 101 Exercise I9 – Count the number of matches


Given a string like:


# # 4 6 # # 7 # 45 # 43 # 65 56 2 # 4345 # # 23


 


Count how many numbers there are in this string


 

Comments (12)

  1. PhilipTaron says:

    perl -ne "$a++ while m/d+/g; print $a;"

  2. Maurits says:

    Spoiler warning… three different ways to do it

    http://www.geocities.com/mvaneerde/regex-i9.txt

  3. Maurits says:

    Here’s my entry in the Obfuscated Perl contest:

    perl -ne "print 0+@{[/d+/g]}"

  4. Maurits says:

    Obfuscated Perl entry #2… mmm… signal-to-noise ratio of 7-to-1 😉

    perl -pe "$_=@{[/d+/g]}"

  5. Maurits says:

    er, 1-to-7 (oops)

  6. Maurits says:

    Thought of two more ways to do it… #4 and #5 on

    http://www.geocities.com/mvaneerde/regex-i9.txt

  7. Regex 101 Exercise I9 – Count the number of matches

    Given a string like:

    # # 4 6 # # 7 #…