home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!math.fu-berlin.de!fauern!Germany.EU.net!mcsun!sunic!dkuug!iesd!iesd.auc.dk!krab
- From: krab@iesd.auc.dk (Kresten Krab Thorup)
- Newsgroups: comp.lang.perl
- Subject: Regexp question/suggestion
- Message-ID: <KRAB.92Sep13154332@xiv.iesd.auc.dk>
- Date: 13 Sep 92 14:43:32 GMT
- Sender: news@iesd.auc.dk (UseNet News)
- Distribution: comp
- Organization: Mathematics and Computer Science, Aalborg University
- Lines: 18
-
- How do I find the number of matches for regexp `R' in a string `S' ?
- My current solution is this:
-
- $string = 'S';
- $mathces = ($string =~ s/R/\&/g);
-
- Now, what is the reason for the fact, that regexp-substitusion has the
- value of the number of the matches, while ordinary regexp-match
- hasn't? To me, it would seem resonable, to have an extra flag, say
- `n' for regular expression matches, so that one could say:
-
- $matches = ($string =~ /R/n);
-
- With $1, $2... set to the values of the LAST match. This would be
- CONSIDERABLY faster than the memory consuming substitution, wouldn't
- it?
-
- /Kresten
-