Skip to content

Commit

Permalink
support limit parameter of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
malmaud committed Jun 25, 2015
1 parent e461f78 commit 75d7c51
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,16 @@ search(s::AbstractString, r::Regex) = search(s,r,start(s))

function replace(s::AbstractString, pat::Regex, r::AbstractString, n::Integer)
# PCRE2 does not support limiting the number of replacements
n > 0 && error("replace with a regex pattern does not support the limit parameter")
n > 1 && error("replace with a regex pattern does not support a limit parameter great than one")
compile(pat)
match_options = pat.match_options
if n==0
match_options |= PCRE.SUBSTITUTE_GLOBAL
else
match_options &= ~PCRE.SUBSTITUTE_GLOBAL
end
PCRE.substitute(pat.regex, bytestring(s), bytestring(r), 0,
pat.match_options | PCRE.SUBSTITUTE_GLOBAL, pat.match_data)
match_options, pat.match_data)
end

immutable RegexMatchIterator
Expand Down

0 comments on commit 75d7c51

Please sign in to comment.