Skip to content

Commit

Permalink
Deprecate callable Regex objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Mar 19, 2018
1 parent 3286d3f commit e238f79
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,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]).

Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down

0 comments on commit e238f79

Please sign in to comment.