-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.py
More file actions
28 lines (24 loc) · 934 Bytes
/
test_parser.py
File metadata and controls
28 lines (24 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import logging
LOG = logging.getLogger()
def cmdStr(text):
#return re.sub(r'@[^! ]* *', "", text) # MEMO:字符串替换
return re.sub(r'@[^\u2005]*[\u2005]*', "", text) # MEMO:字符串替换
def matchedStr(cmdStr):
LOG.debug('remove at, cmdStr=%s' % cmdStr)
# b'@\xe5\x88\x98\xe5\xbe\xb7 !#: ls'
# b'@\xe5\x88\x98\xe5\xbe\xb7\xe2\x80\x85!#: ls'
match = re.match(r'!(?P<code>.*?):[[:space:]]*(?P<text>.*)', cmdStr, re.DOTALL)
# logger.debug(msg.text.encode())
if match:
LOG.debug('matched' + str(match.groups()))
code = match.group('code')
text = match.group('text')
return (code, text)
str1 = '@刘德 !?: 1900489595' # ('?', '1900489595')
str1 = '!?: 9890960816194' # ('?', '\u20059890960816194')
cstr = cmdStr(str1)
print('cmdStr: %s' % cstr)
print(matchedStr(cstr))