java.util.regex Code Samples
- How do I use quantifier in regex?
- How do I write negated character class regex?
- How do I use possessive quantifier regex?
- How do I write union character class regex?
- How do I use predefined character classes regex?
- How do I write range character class regex?
- How do I use reluctant quantifier regex?
- How do I write character class intersection regex?
- How do I combile character classes with quantifier?
Page 2 of 2 |
Prev
|
Next
How do I find and replace string?
The code below demonstrates the use Matcher.appendReplacement() and Matcher.appendTail() methods to create a program to find and replace a sub string within a string.
Another solution that can be used to search and replace a string can be found on the following example: How do I create a string search and replace using regex?.
Here is the result of the above code:
Input : Please use your Pen to answer the question, black pen is prefered. Output: Please use your pencil to answer the question, black pencil is prefered.