Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created April 9, 2014 23:30
Show Gist options
  • 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