Skip to content

Commit

Permalink
#671: updated substring replacement function regex
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld committed Jun 15, 2022
1 parent b6e284b commit 862437e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dtale/column_replacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_column(self, data):
value = re.escape(value)
if is_char:
value = "[{value}]+".format(value=value)
regex_pat = re.compile(r"^ *{value} *$".format(value=value), flags=flags)
regex_pat = re.compile(r"^.*{value}.*$".format(value=value), flags=flags)
replace_with = get_replacement_value(self.cfg, "replace")
return data[self.col].replace(regex_pat, replace_with, regex=True)

Expand All @@ -100,7 +100,7 @@ def build_code(self, data):

regex_exp = "r'^ *{value} *$'.format(value=re.escape({value}))"
if is_char:
regex_exp = "r'^ *[{value}]+ *$'.format(value=re.escape({value}))"
regex_exp = "r'^.*[{value}].*$'.format(value=re.escape({value}))"
regex_exp = regex_exp.format(value=value)

replace_with = get_replacement_value_as_str(self.cfg, "replace", data[self.col])
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/popups/replacement/Strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const buildCode = (col: string, colType: string, cfg: StringsConfig): Cre
return [
'import re',
'',
`regex_pat = re.compile(r'^ *${valStr} *$', flags=${flags})`,
`regex_pat = re.compile(r'^.*${valStr}.*$', flags=${flags})`,
`df.loc[:, '${col}'] = df['${col}'].replace(regex_pat, ${replaceVal}, regex=True)`,
];
};
Expand Down

0 comments on commit 862437e

Please # to comment.