[Tutor] delete strings from specificed words

Peter Otten __peter__ at web.de
Wed Jan 10 04:37:09 EST 2018


YU Bo wrote:

> ```text
> The registers rax, rcx and rdx are touched when controlling IBRS
> so they need to be saved when they can't be clobbered.
> 
> diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
> index 45a63e0..3b9b238 100644
> ...
> ```
> I want to delete string from *diff --git* to end, because too many code is
> here

Use str.split() or str.partition() and only keep the first part: 

>>> text = """The registers rax, rcx and rdx are touched when controlling 
IBRS
... so they need to be saved when they can't be clobbered.
... 
... diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
... index 45a63e0..3b9b238 100644
... """
>>> cleaned_text = text.partition("diff --git")[0].strip()
>>> print(cleaned_text)
The registers rax, rcx and rdx are touched when controlling IBRS
so they need to be saved when they can't be clobbered.




More information about the Tutor mailing list