ramirez ramirez - 3 months ago 17
Java Question

How to search then select a string among double quote in JAVA?

I have a variable named

MyText
in type of
String
as below:

"XYZ_abcdefgh..."


Note that
abcdefgh...
means that we don't know exactly what is it (simply say: it changes).

Now I want to select all of
XYZ_abcdefgh...
by this mean and put it in another variable like
MyExportedText
:

SELECT ALL STRINGS BETWEEN DOUBLE QUOTE WITCH STARTS WITH 'XYZ'

Thanks.

Answer

Take a look at Java capturing groups. Essentially you can enclose part of the regex in round brackets to "capture" them and extract them from the input String.