javascript - Using regular expressions to find and replace within a string with additional style -


i have raw text need output, have search box highlight parts of text match entered in search box.

this works, find search box contents:

replace="<span class='highlight'>"+find+"</span>"; var results = drawstring.replace(new regexp(find, 'gi'), replace); return results; 

my problem want match regardless of case i'll replacing exact input of user. want retain case of original value before replace, how can done.

you can use matched string inside replace value:

replace="<span class='highlight'>$&</span>"; 

see: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string/replace#specifying_a_string_as_a_parameter


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -