fork download
  1. import re
  2.  
  3. regex = r"^(\w+)(?:\/.*)?$"
  4. test_str = ("Foo/Bar\n"
  5. "Foobar")
  6. result = re.sub(regex, r'\1', test_str, 0, re.MULTILINE)
  7.  
  8. if result:
  9. print (result)
Success #stdin #stdout 0.02s 9616KB
stdin
Standard input is empty
stdout
Foo
Foobar