perlperlperl has asked for the wisdom of the Perl Monks concerning the following question:
Hi. I was wondering if there is a capability in Perl to register a call back to the regex engine and call that registered function each time a particular match is made. For example, consider the string: "this is a string". I want to count the number of 's' in the string. Normally I would use a string utility and pop one character at a time and count the 's' as I come across them. I think a better way would be to make a regex that has a callback to a character class, \s\ in this case, and increments a global variable each time it matches an 's'.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: callback for regex engine
by LanX (Saint) on Jun 20, 2013 at 22:51 UTC | |
Re: callback for regex engine
by kennethk (Abbot) on Jun 20, 2013 at 23:38 UTC | |
Re: callback for regex engine
by zork42 (Monk) on Jun 21, 2013 at 09:26 UTC | |
by ikegami (Patriarch) on Jun 23, 2013 at 00:55 UTC |
Back to
Seekers of Perl Wisdom