How to count with regex.

Jun 18, 2018 at 4:06pm
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?
Jun 18, 2018 at 4:15pm
closed account (E0p9LyTq)
https://duckduckgo.com/?q=regex+count+occurrences&t=ffsb&ia=qa
Jun 18, 2018 at 5:39pm
it might be easier to read (and write, and debug, etc) if you do a count-if though?
Last edited on Jun 18, 2018 at 5:39pm
Jun 18, 2018 at 6:43pm
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 ?
Jun 19, 2018 at 5:56am
@Thomas1965 "Why don't you use a stringstream or even strtok to split replace and count ?"

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