我有一个字符串uint16_t 14bitarr_get(unsigned char* arr, unsigned int index) {
EightValues* accessPointer = (EightValues*)arr;
accessPointer += index >> 3; //select the right structure in the array
switch(index & 7) { //use the last three bits of the index to access the right bitfield
case 0: return accessPointer->v0;
case 1: return accessPointer->v1;
case 2: return accessPointer->v2;
case 3: return accessPointer->v3;
case 4: return accessPointer->v4;
case 5: return accessPointer->v5;
case 6: return accessPointer->v6;
case 7: return accessPointer->v7;
}
}
a
我想基本上做以下几点
a="to be removed blah blah \r\nrow 2 blah blah\r\nrow 3 more blah blah \r\nto be removed more blah blah \r\nrow 5 final blah blah"
以便输出如下所示:
a=a.replace_all("to be removed...\r\n" ,"")
然而,我只知道线是如何开始的,而不是其余的
答案 0 :(得分:3)
使用re.sub
并添加一个重复.
的通配符*
,但不要贪图?
\r\n
:
>>> import re
>>> a = "to be removed blah blah \r\nrow 2 blah blah\r\nrow 3 more blah blah \r\nto be removed more blah blah \r\nrow 5 final blah blah"
>>> a = re.sub(r'to be removed.*?\r\n', '', a)
>>> a
'row 2 blah blah\r\nrow 3 more blah blah \r\nrow 5 final blah blah'
答案 1 :(得分:1)
不使用正则表达式的另一种方法:
Y
答案 2 :(得分:0)
另一种尝试可能是search
模块的sub
和re
功能的组合 -
>>> a = "to be removed blah blah \r\nrow 2 blah blah\r\nrow 3 more blah blah \r\nto be removed more blah blah \r\nrow 5 final blah blah"
>>> r = re.sub(re.search(r'to be removed blah blah[\s]+', a,re.I).group(), '', a)
>>> print r