How to use regexp on file, line by line, in Python

后端 未结 7 1886
[愿得一人]
[愿得一人] 2020-12-30 00:24

Here is my regexp: f\\(\\s*([^,]+)\\s*,\\s*([^,]+)\\s*\\)

I\'d have to apply this on a file, line by line. The line by line is OK, simple reading from

7条回答
  •  一生所求
    2020-12-30 01:20

    Another way to do

    import re
    [line for line in open('file.txt') if re.match(r'f\(\s*([^,]+)\s*,\s*([^,]+)\s*\)',line)]
    

提交回复
热议问题