Skip to content

Commit 87e7338

Browse files
committed
Deprecate callable Regex objects
1 parent e090afd commit 87e7338

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,8 @@ Deprecated or removed
10781078
* `contains` has been deprecated in favor of a more general `occursin` function, which
10791079
takes its arguments in reverse order from `contains` ([#26283]).
10801080

1081+
* `Regex` objects are no longer callable. Use `occursin` instead ([#26283]).
1082+
10811083
* The methods of `range` based on positional arguments have been deprecated in favor of
10821084
keyword arguments ([#25896]).
10831085

base/deprecated.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,10 @@ end
14701470
# PR #26283
14711471
@deprecate contains(haystack, needle) occursin(needle, haystack)
14721472
@deprecate contains(s::AbstractString, r::Regex, offset::Integer) occursin(r, s, offset=offset)
1473+
function (r::Regex)(s)
1474+
depwarn("`(r::Regex)(s)` is deprecated, use `occursin(r, s)` instead.", :Regex)
1475+
occursin(r, s)
1476+
end
14731477

14741478
# Issue #25786
14751479
@deprecate_binding DevNull devnull

base/regex.jl

-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ function occursin(r::Regex, s::SubString; offset::Integer=0)
153153
r.match_data)
154154
end
155155

156-
(r::Regex)(s) = isfound(r, s)
157-
158156
"""
159157
match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])
160158

0 commit comments

Comments
 (0)