I would like to highlight a part of the string with the searchedText string.
Exemple:
I have a product reference abcDeFg (case sensitive) and someone search for product with reference “def”. The result should be abc<span class="hl">DeF</span>g
Problem: the result should be the highlighted product reference (case sensitive)
Excepted result: abc<span class='light'>DeF</span>g
My result: abc<span class='light'>def</span>g (def is minuscule)
Currently I am using
<#assign prodRef = product.getReference()>
<#if (prodRef?lower_case?index_of(searchedText?lower_case) > -1)>
<#assign textToReplace = "<span class='light'>" + searchedText + "</span>">
${product.reference?replace(searchedText, textToReplace, "i")}
</#if>
Can someone tell me how fix this issue?
Basically i need replace string function that will keep the case sensitiveness of the original reference.
A regular expression can do this alone:
However, then
searchTextmust not contain any characters that has special meaning in regular expressions (or those must be escaped).