@@ -118,6 +118,13 @@ def get_transaction_type(
118118 return txn_type , dividend_rate
119119
120120
121+ def get_parsed_scheme_name (scheme ) -> str :
122+ scheme = re .sub (r"\((formerly|erstwhile).+?\)" , "" , scheme , flags = re .I | re .DOTALL ).strip ()
123+ scheme = re .sub (r"\((Demat|Non-Demat).*" , "" , scheme , flags = re .I | re .DOTALL ).strip ()
124+ scheme = re .sub (r"\s+" , " " , scheme ).strip ()
125+ return re .sub (r"[^a-zA-Z0-9_)]+$" , "" , scheme ).strip ()
126+
127+
121128def parse_transaction (line ) -> Optional [ParsedTransaction ]:
122129 for regex in (TRANSACTION_RE1 , TRANSACTION_RE2 , TRANSACTION_RE3 ):
123130 if m := re .search (regex , line , re .DOTALL | re .MULTILINE | re .I ):
@@ -189,9 +196,7 @@ def process_detailed_text(text):
189196 elif m := re .search (SCHEME_RE , line , re .DOTALL | re .MULTILINE | re .I ):
190197 if current_folio is None :
191198 raise CASParseError ("Layout Error! Scheme found before folio entry." )
192- scheme = re .sub (r"\(formerly.+?\)" , "" , m .group ("name" ), flags = re .I | re .DOTALL ).strip ()
193- scheme = re .sub (r"\s+" , " " , scheme ).strip ()
194- scheme = re .sub (r"\W+$" , "" , scheme ).strip ()
199+ scheme = get_parsed_scheme_name (m .group ("name" ))
195200 if curr_scheme_data is None or curr_scheme_data .scheme != scheme :
196201 if curr_scheme_data :
197202 folios [current_folio ].schemes .append (curr_scheme_data )
0 commit comments