Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created October 16, 2013 11:24
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 mikebaldry/7006265 to your computer and use it in GitHub Desktop.
Save mikebaldry/7006265 to your computer and use it in GitHub Desktop.
def extract_highlights(highlighted_string)
results = []
str = highlighted_string.dup
while start_index = str.index("<em>")
match_length = str[start_index..-1].index("</em>") - 4
results << [start_index, match_length]
before_part = str[0...start_index]
highlight_part = str[start_index + 4, match_length]
after_part = str[start_index + 4 + match_length + 5..-1]
str = [before_part, highlight_part, after_part].join
end
results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment