Let's examine the first one to explain what it is doing and how you could find this out. As usual, start at the right of the expression with tr/y// where tr is the transliteration operator. Note that this operator does not work with regular expressions but just deals with lists of characters. Every character in the first list (y) found in the operand ($str) is replaced by the equivalent character in the second list (empty) or if, as in this case, there is no equivalent character in the second list, the matching character is left as it is. tr then returns the number of characters in the operand so treated. If there were no explicit operand it would use $_ by default.
$ perl -E '$str="Fly guys try yoyos"; my $c = $str =~ tr/y//; say $c;' 5
How do you discover all this? Well, perldoc will tell you all about tr - you just need to know that the docs are the place to look. Try perldoc -f tr for all the good stuff.
With that in mind, can you now work out what is going on in the second example?
🦛
In reply to Re: Confused by RegEx count
by hippo
in thread Confused by RegEx count
by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |