-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_re.py
More file actions
63 lines (57 loc) · 1.63 KB
/
test_re.py
File metadata and controls
63 lines (57 loc) · 1.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import logging
logger = logging.getLogger()
def ccc(text):
import re
match = re.match(r'!(.*?): (.*)', text)
print('~~~')
if match:
print('mmmm')
logger.debug('matched' + str(match.groups()))
code = match.group(1)
parm = match.group(2)
print (code + parm)
#ccc('!#: ls')
def test1(text):
import re
print('-1-: %s' % text)
#match = re.match(u'(@[^ !]* ?)?!(?P<code>.*?): (?P<text>.*)', text)
match = re.match(r'(@[^!]*)?!(?P<code>.*?): (?P<text>.*)', text)
if match:
print(' matched!')
logger.debug('matched' + str(match.groups()))
code = match.group('code')
text = match.group('text')
print(' code: ' + code)
return
print(' not match')
def test2(text):
import re
print('-2-: %s' % text)
match = re.match(r'!(.*?): (.*)', text)
if match:
print(' matched!')
logger.debug('matched' + str(match.groups()))
code = match.group(1)
text = match.group(2)
print(' code: ' + code)
return
print(' not match')
test1(' !#: ls=NotMatch')
#test2(' !#: ls')
test1('!#: ls')
test1('@a !#: ls')
test1('@刘德 !#: ls')
print('@刘德 !#: ls'.encode('utf_8'))
#test2('!#: ls')
b = b'@\xe5\x88\x98\xe5\xbe\xb7\xe2\x80\x85!#: ls'
print('s=' + b.decode("utf_8"))
s = b.decode("utf_8")
print(s.encode())
test1(b.decode("utf_8"))
cmdStr = s.replace(u'@[^! ]*', '')
cmdStr = s.replace('!.*', '')
cmdStr = re.sub(r'@[^! ]*', "", s)
print('cmdStr: %s' % cmdStr)