replaceAll « word « Java Regex Q&A

Home
Java Regex Q&A
1.Development
2.find
3.group
4.Match
5.matcher
6.number
7.Operation
8.parse
9.Pattern
10.replace
11.validation
12.word
Java Regex Q&A » word » replaceAll 

1. Censoring selected words (replacing them with ****) using a single replaceAll?    stackoverflow.com

I'd like to censor some words in a string by replacing each character in the word with a "*". Basically I would want to do

String s = "lorem ipsum dolor sit";
s ...

2. Replace a word that is not on a string    stackoverflow.com

I'm trying to replace a word in a file whenever it appears except when it is contained in a string: So I should replace this in

The test in this line ...

3. Rearrange words in java    stackoverflow.com

I am trying to do a word replace tool to reduce google translate gibberish. What i need to do right now is: i have a String like : lalala text lalatxt. and i need ...

4. Regular Expression - replaceAll() - how to replace words?    coderanch.com

Hiya, I have this regex to replace all instances of myWord: String oldWord = "oldWord"; String newWord = "newWord"; String sentence = "some sentence that contains " + oldWord; String newSentence = replaceWordsInSentence(sentence, oldWord, newWord); private String replaceWordsInSentence(String sentence, String oldWord, String newWord) { return sentence.replaceAll("\b" + oldWord + "\b", newWord); } ...it works in most instances, but when oldWord is ...

5. Regular Expression - replaceAll() - how to replace words?    forums.oracle.com

I see three problems: - You must use " b" instead of "\b" (remember: you need to escape the backslash for the string literal) - You should use Pattern.quote(oldWord) to avoid special characters to be interpreted as regex in oldWord - You should use Matcher.quoteReplacement(newWord) for a similar reason Fixing those made the code work for me.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.