Skip to content

Commit be6d2ae

Browse files
author
Renne Rocha
committed
Fixed regular expression search for dollar codes
1 parent 04ae325 commit be6d2ae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

price_parser/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ def or_regex(symbols: List[str]) -> Pattern:
109109
DOLLAR_CODES = [k for k in CURRENCY_CODES if k.endswith('D')]
110110
_DOLLAR_REGEX = re.compile(
111111
r'''
112-
\b
112+
(\b
113113
(?:{}) # currency code like NZD
114114
(?=
115115
\$? # dollar sign to ignore if attached to the currency code
116116
(?:[\W\d]|$) # not a letter
117-
)
117+
))
118118
'''.format('|'.join(re.escape(k) for k in DOLLAR_CODES)),
119119
re.VERBOSE,
120120
)
@@ -142,7 +142,7 @@ def or_regex(symbols: List[str]) -> Pattern:
142142
OTHER_CURRENCY_SYMBOLS = sorted(OTHER_CURRENCY_SYMBOLS_SET,
143143
key=len, reverse=True)
144144

145-
_search_dollar_code = re.compile("|".join(DOLLAR_REGEXES), re.VERBOSE).search
145+
_search_dollar_code = _DOLLAR_REGEX.search
146146
_search_other_particular_regexes = re.compile("|".join(OTHER_PARTICULAR_REGEXES), re.VERBOSE).search
147147
_search_safe_currency = or_regex(SAFE_CURRENCY_SYMBOLS).search
148148
_search_unsafe_currency = or_regex(OTHER_CURRENCY_SYMBOLS).search

0 commit comments

Comments
 (0)