I have a String such as
somet3x70rnumb3r5.3.1*@:ch4r5*
I need to wrap everything that isn't *
, star character, with a Pattern Quote \Q...\E
and replace the *
with .*
. It should give this:
\Qsomet3x70rnumb3r5.3.1\E.*\Q@:ch4r5\E.*
I can do this with string traversal, splitting on *
(or any character I specify), and building a string step by step, but I'd like to do use regexes and Pattern class utilities if possible.
Another example with specified character ?
which would be replaced by .
:
123?4?
should give
\Q123\E.\Q4\E.
I was thinking of using groups, but I need groups around every zone because each has to be either wrapped or replaced by another character.
My goal is to create a Pattern String
from a given String
but only consider the areas matching the specified character and ignoring the rest (even if it contains regex patterns).