Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make startswith, endswith work with Regex #29790

Merged
merged 17 commits into from
Feb 1, 2019
Next Next commit
Add startswith, endswith for Regex
  • Loading branch information
dalum committed Oct 24, 2018
commit c19fb8209a82f47980a12107462042d9305ab921
10 changes: 10 additions & 0 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ function occursin(r::Regex, s::SubString; offset::Integer=0)
r.match_data)
end

function startswith(s::AbstractString, r::Regex)
dalum marked this conversation as resolved.
Show resolved Hide resolved
rr = Regex("^"*r.pattern, r.compile_options, r.match_options)
return occursin(rr, s)
end

function endswith(s::AbstractString, r::Regex)
dalum marked this conversation as resolved.
Show resolved Hide resolved
rr = Regex(r.pattern*"\$", r.compile_options, r.match_options)
return occursin(rr, s)
end

"""
match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])

Expand Down