mirror of
https://github.com/ilri/csv-metadata-quality.git
synced 2024-11-22 05:45:02 +01:00
Test Python regular expression matches directly
Match objects always have a boolean value of True. See: https://docs.python.org/3.7/library/re.html
This commit is contained in:
parent
7b5db1f5d9
commit
42920e9c7c
@ -69,7 +69,7 @@ def separators(field):
|
||||
# After splitting, see if there are any remaining "|" characters
|
||||
match = re.findall(r'^.*?\|.*$', value)
|
||||
|
||||
if len(match) > 0:
|
||||
if match:
|
||||
print(f'Invalid multi-value separator: {field}')
|
||||
|
||||
return field
|
||||
|
@ -24,8 +24,8 @@ def whitespace(field):
|
||||
pattern = re.compile(r'\s{2,}')
|
||||
match = re.findall(pattern, value)
|
||||
|
||||
if len(match) > 0:
|
||||
print(f'Excessive whitespace: {value}')
|
||||
if match:
|
||||
value = re.sub(pattern, ' ', value)
|
||||
|
||||
# Save cleaned value
|
||||
@ -53,7 +53,7 @@ def separators(field):
|
||||
pattern = re.compile(r'\|')
|
||||
match = re.findall(pattern, value)
|
||||
|
||||
if len(match) > 0:
|
||||
if match:
|
||||
print(f'Fixing invalid multi-value separator: {value}')
|
||||
|
||||
value = re.sub(pattern, '||', value)
|
||||
|
Loading…
Reference in New Issue
Block a user