python - 如果找到一个字符,则从字符串中删除所有行,python
问题描述
我有一个像这样的字符串:
FIRST CONTINUATION PAGE FOR ITEM 29 – Establishment Information
Add Second Continuation Page for #29
<<
/ASCII85EncodePages false
/AllowTransparency false
/AutoPositionEPSFiles true
/AutoRotatePages /None
/Binding /Left
/CalGrayProfile (Dot Gain 20%)
/CalRGBProfile (sRGB IEC61966-2.1)
我想在找到 << 字符后删除文件中的所有行。我如何使用正则表达式来做到这一点
解决方案
最简单的解决方案:
your_string = "whatever.................."
sliced_string = your_string.split("<<")[0]
就是这样。