fork download
  1. import re
  2. # Adding anchors:
  3. print( re.sub("^.*$", "(replacement)", "sample text") )
  4. # Using the count=1 argument
  5. print( re.sub(".*", "(replacement)", "sample text", count=1) )
  6. # If you want to replace non-empty lines:
  7. print( re.sub(".+", "(replacement)", "sample text") )
  8.  
  9.  
Success #stdin #stdout 0.03s 9420KB
stdin
Standard input is empty
stdout
(replacement)
(replacement)
(replacement)