Tag:python
Article From:https://segmentfault.com/q/1010000012148838
Question:

There are two lines in the file file.txt as follows:
one:[“nihao”,”hello”]
two:[“shijie”,”world”]

How do I match one and print [“nihao”, “hello”]?

Answer 0:

Get all the contents of the file first, and then regular

p = re.compile('one:(\[.*?\])')
arr = p.findall(content)
print arr[0]

Answer 1:
import re
print re.search(r'one\:(.*)', s).group(1)

Leave a Reply

Your email address will not be published. Required fields are marked *