diff --git a/NEWS.md b/NEWS.md index fb2ab269fc2c4..d3c777ca421a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1078,6 +1078,8 @@ Deprecated or removed * `contains` has been deprecated in favor of a more general `occursin` function, which takes its arguments in reverse order from `contains` ([#26283]). + * `Regex` objects are no longer callable. Use `occursin` instead ([#26283]). + * The methods of `range` based on positional arguments have been deprecated in favor of keyword arguments ([#25896]). diff --git a/base/deprecated.jl b/base/deprecated.jl index cc6d80736868d..4cf1a50abf81f 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1470,6 +1470,10 @@ end # PR #26283 @deprecate contains(haystack, needle) occursin(needle, haystack) @deprecate contains(s::AbstractString, r::Regex, offset::Integer) occursin(r, s, offset=offset) +function (r::Regex)(s) + depwarn("`(r::Regex)(s)` is deprecated, use `occursin(r, s)` instead.", :Regex) + occursin(r, s) +end # Issue #25786 @deprecate_binding DevNull devnull diff --git a/base/regex.jl b/base/regex.jl index d05a8275a9792..cec07bb3ea5d8 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -153,8 +153,6 @@ function occursin(r::Regex, s::SubString; offset::Integer=0) r.match_data) end -(r::Regex)(s) = isfound(r, s) - """ match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])