Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- filePath = '/Users/u/filewithspecialcharacters.csv'
- fileEncoding = 'iso-8859-1'
- pattern = r"^[a-zA-Z0-9_;:!@?'.#(){}*|~/+%&<>,–`=\"\s\-\$\[\]\^\\]*$"
- compiledPattern = re.compile(pattern)
- count = 0
- with open(filePath,'r',encoding=fileEncoding) as file:
- for line in file:
- if not re.match(compiledPattern, line):
- count = count + 1
- print(line)
- print('No of lines with special characters: ',count)
Add Comment
Please, Sign In to add comment