How to use regular expressions to get all lines from text file that start with specific character in Python

1 Answer

0 votes
import re

fh = open("d:\data.txt")

for line in fh:
    if re.search(r"p.*", line):
        print(line.rstrip())

fh.close()


'''
run:

python
php

'''

 



answered Dec 25, 2017 by avibootz
...