How to count with regex.

This is just a thought, but if you were replacing words with regex and you wanted to count how many words you replaced then how would you do that?
closed account (E0p9LyTq)
https://duckduckgo.com/?q=regex+count+occurrences&t=ffsb&ia=qa
it might be easier to read (and write, and debug, etc) if you do a count-if though?
Last edited on
Have a look at the second answer.
https://stackoverflow.com/questions/27680520/stdregex-replace-replace-n-occurences-and-get-number-of-substitutions

Why don't you use a stringstream or even strtok to split replace and count ?
@Thomas1965 "Why don't you use a stringstream or even strtok to split replace and count ?"

I haven't heard of them.
Stringstreams are very useful so you should have a look at them.
For this task maybe stick with regex.
Ok thanks for the tip, I'll check them out.
Topic archived. No new replies allowed.