Skip to content

Instantly share code, notes, and snippets.

@Houdini
Created Aug 9, 2010
Embed
What would you like to do?
- (String) highlight_text:input_string {
return input_string
if (search_string !== '') {
var regex = new RegExp(search_string, 'ig');
var start_index = input_string.search(regex);
var new_substring = '<strong>' + input_string.substring(start_index, search_string.length) + '</strong>';
return input_string.substring(0, start_index) + new_substring + input_string.substring(search_string.length + start_index, input_string.length);
} else {
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment