fork(1) download
  1. import re
  2. text = "I studied in King Saud University, which is in Riyadh, the capital of Saudi Arabia"
  3. result = re.sub(r"\b[A-Z]\w*(?:\s+[A-Z]\w*)+", lambda x: "".join(c[0] for c in x.group().split()), text)
  4. print(result)
Success #stdin #stdout 0.03s 9628KB
stdin
Standard input is empty
stdout
I studied in KSU, which is in Riyadh, the capital of SA