Skip to content
Advertisement

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

How to replace all substrings?

I want to replace all the text within brackets to uppercase letters for any String object. For example if the text is – Hi (abc), how (a)re (You)?” , output should be – Hi ABC, how Are YOU? . I tried to use StringUtils.SubstringBetween(), but that replaces only the first substring between (). Using regex, I suppose the group() method

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

How to replace text symbol in Java or Text Editor

I want to replace the symbol after the second comma. I know how to group until the second comma. I tried below. But I don’t know how to replace from “/” to “?” after the second comma I expected below. GROUP/COMPANY,USER/PASSWORD,BIRTHDAY:”2010/01/01″,ADDRESS:”US/ALASKA” ↓ GROUP/COMPANY,USER/PASSWORD,BIRTHDAY:”2010?01?01″,ADDRESS:”US?ALASKA” Answer In Java Note that the logic of below code is “after finding the first numeric value”,

How can i remove different strings from one string?

I’ve been searching for a while but other answers are quiet different to what im trying to do. I’m trying to delete prepositions from a string but i wonder if there is any way to delete them without doing it one by one like i’m doing right now: (I’m trying to delete spanish prepositions like (de, del, el, la)) Once

Replace ASCII codes and HTML tags in Java

How can i achieve below expecting results without using StringEscapeUtils ? Current Results: Expecting Results: Already checked: How to unescape HTML character entities in Java? PS: This is just a sample example, input may vary. Answer Your regexp is for html tags <something> would be matched byt the html entities will not be matched. Their pattern is something like &.*?;

Advertisement