@@ -459,7 +459,10 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=None):
459
459
regex : boolean, default None
460
460
- If True, assumes the passed-in pattern is a regular expression.
461
461
- If False, treats the pattern as a literal string
462
- - If pat is single special character, default regex is False.
462
+ - If `pat` is a single character and `regex` is not specified, `pat`
463
+ is interpreted as a string literal. If `pat` is also a regular
464
+ expression symbol, a warning is issued that in the future `pat`
465
+ will be interpreted as a regex, rather than a literal.
463
466
- Cannot be set to False if `pat` is a compiled regex or `repl` is
464
467
a callable.
465
468
@@ -580,7 +583,7 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=None):
580
583
"regex=False" )
581
584
# if regex is default None, and a single special character is given
582
585
# in pat, still take it as a literal, and raise the Future warning
583
- if regex is None and len (pat ) == 1 and re .findall ( r"\W" , pat ):
586
+ if regex is None and len (pat ) == 1 and re .escape ( pat ) != pat :
584
587
warnings .warn ("'{}' is interpreted as a literal in " .format (pat ) +
585
588
"default, not regex. It will change in the future." ,
586
589
FutureWarning )
0 commit comments