I got one more problem. I dont' think Man page mentioned
about second matching on the same string, when I read it.
I tried call "i = regexec(r, argv[2]);" twice, but didn't move
forward after first match. I did found however
"i = regexec(r, r->endp[0]);" matches the second substring.
but I don't think it's meant to be used this way.
How do you match same pattern more than twice on the same line?
Well, typically, you would find a point in the line after the first
match, and use regexec to match there.
Why don't you think it's meant to be used this way? What seems unusual
to you about using the endpoint of a previous match as the starting place
to look to see whether there are any more matches? Why would you think
that it would "move forward" after the first match?
Let's translate this all into plain language.
Consider this string. We need a name for it, let's call it "Bob".
"hello, world, hello, dolly, hello, sailor".
Now, I ask you: Does Bob contain the word hello? If so, where?
You respond with something like:
Yes: ">hello<, world, hello, dolly, hello, sailor".
Okay. Now I ask you: Does Bob contain the word hello? If so, where?
Why would your answer be different? I didn't ask you a different
question. Nothing changed. The string isn't different from what it
used to be. It would be ridiculous for your answer to be different.
Now, imagine instead that I asked you "Does Bob contain the word hello
somewhere after the 5th character? If so, where?", then you might
respond:
Yes: ", world, >hello<, dolly, hello, sailor".
Computers do exactly what you ask them to. They do not do what you
meant, and they don't care whether you just asked them that two seconds
ago; they're just going to keep answering the question you asked.
-s