The simple answer is, find these people, or their friends or both, and watch them 24/7. Catch them when they are about to act. Interrogate them. Find their terrorist allies and where they are, and go destroy them.
The how of it is a little more complicated, though. How far do you go to find these terrorists' allies?
Can you exterminate them without incurring innocent casualties (probably not in most cases) ?
If not, what are acceptable bystander casualties? Any? None?
If none, then what do you do? Wait to be attacked again? Watch them forever, 24/7?
When your enemy doesn't wade into battle, waving standards and adhering to battle lines, it makes it extremely difficult to stop them before they attack - especially when they don't seem to give a damn about their own lives.
This is why I believe that the best answer to this problem is to attack the ideology. To get it at its source: children. Teach children right from wrong. Raise them in the way they should go. Do not let them fall victim to radical Islamist beliefs.