Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created April 9, 2014 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlobaldassi/10329790 to your computer and use it in GitHub Desktop.
Save carlobaldassi/10329790 to your computer and use it in GitHub Desktop.
Naïve reverse rsearch
function Base.rsearch(str::Union(ByteString,SubString), re::Regex, idx::Integer = endof(str))
sidx = 1
lastr = 0:-1
while sidx <= endof(str)
r = search(str, re, sidx)
isempty(r) && return lastr
last(r) > last(lastr) && (lastr = r)
sidx = nextind(str, first(r))
end
return lastr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment