Skip to content

Commit

Permalink
regreplace
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurea committed Dec 11, 2024
1 parent 73c19b4 commit 8977862
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pixell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,11 @@ def replace(istr, ipat, repl):
if ostr == istr: raise KeyError("Pattern not found")
return ostr

def regreplace(istr, ipat, repl, count=0, flags=0):
ostr, n = re.subn(ipat, repl, istr, count=count, flags=flags)
if n == 0: raise KeyError("Pattern not found")
return ostr

# I used to do stuff like a[~np.isfinite(a)] = 0, but this should be
# lower overhad and faster
def remove_nan(a):
Expand Down

0 comments on commit 8977862

Please sign in to comment.