I am looking for a way to count the occurence of matches when the search term is contained several times in one line. I take it that storing a string in an array and to run them through a for-loop is only helpful, when the regexp only shows up once per line. In my case I know this not to be the case.
Presumably there is some internal variable of the regexp procedure that stores the rest of the string, that is following the (first) match. This could then be used like this:
to count the matches, including several ones within one line. Of course, $_ isn't the variable I am looking for.#! C:\Programme\Perl\bin\ use warnings; use strict; our $count=0; our $teststring="Long test string \n that includes the word we search, + which is test (to test it)\n several times in one line like this: te +st test test"; our $residual=$teststring; while ($residual) { if ($residual=~"test") { $residual=$_; $count++; } } print $count;
Thanks in advance for any hints.
In reply to Counting multiple matches of RegExp in single line by New Novice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |