Created
September 13, 2012 18:37
-
-
Save meglio/3716561 to your computer and use it in GitHub Desktop.
Highlights numerical string in numerical string, while both strings are free formatted and containing more then just digits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function highlightNumerical(searchString, inString) { | |
// http://jsfiddle.net/meglio/p9KUV/ | |
if (typeof searchString == "object") { | |
if (searchString.length) | |
searchString = searchString[0] | |
else | |
return inString | |
} | |
var prefix = '<strong class="highlight">', suffix = '</strong>', | |
normSearch = $.trim(searchString.replace(/\D/g, '')) | |
if (normSearch == '') | |
return inString | |
var expr = '('+ normSearch.split('').join('\\D*') + ')', | |
r = new RegExp(expr, 'g'); | |
return inString.replace(r, prefix+'$1'+suffix); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment