Skip to content

Tag: replace

Apache Lucene to replace found terms

I’m looking for a way to find-and-replace words basing on queries in a text using Apache Lucene. Example – I have a text “Happy New Year!” and Lucene query “year~2” with fuzzy-detection and some replace characters (“###”). As the result I want the following – “Happy New ###!”. Is there a way to achieve this using Apache Lucene only? Answer

Replacing a portion of string entry

I have a list of Strings, and would want to replace a few characters of the individual string entry by new string and add to the list. For eg: I believe it can be achieved with regex, and I need some inputs here. Suggestions? Answer Use this code for your problem

Regex to consolidate multiple rules

I’m looking at optimising my string manipulation code and consolidating all of my replaceAll’s to just one pattern if possible Rules – strip all special chars except – replace space with – condense consecutive – ‘s to just one – Remove leading and trailing -‘s My code – Does the job but obviously looks shoddy. My test assertions – Answer