| 1 | |
package com.aurea.maven.plugins.sonic.utils; |
| 2 | |
|
| 3 | |
import java.util.regex.Matcher; |
| 4 | |
import java.util.regex.Pattern; |
| 5 | |
|
| 6 | 0 | public class RegexUtil { |
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
public static String applyReplaceFunction(String text, String str, String replacement) { |
| 17 | |
|
| 18 | 0 | Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}"); |
| 19 | 0 | Matcher matcher = pattern.matcher(text); |
| 20 | |
|
| 21 | 0 | StringBuffer result = new StringBuffer(); |
| 22 | 0 | while (matcher.find()) { |
| 23 | 0 | String argument = matcher.group(1); |
| 24 | 0 | matcher.appendReplacement(result, argument.replace(str, Matcher.quoteReplacement(replacement))); |
| 25 | 0 | } |
| 26 | 0 | matcher.appendTail(result); |
| 27 | |
|
| 28 | 0 | return result.toString(); |
| 29 | |
} |
| 30 | |
|
| 31 | |
} |