'Add constant when replaceAll by regex
I have a regex for exclude non digit symbols:
\\D
And i need to replace all non digit symbols to spaces:
"145632afaf214+--)(".replaceAll("\\D", ""); // 145632214
Can I add to result some constant at the beginning string if i have result from the regex? I would see result like this:
"145632afaf214+--)(".replaceAll(improvedRegex, ""); // CONST145632214
However:
"qwqtyafaf+--)(".replaceAll(improvedRegex, ""); // ""
EDIT: This regex adds CONST to the string but doesn't filter digits:
replaceAll("(^.+)", "CONST$1")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
