Expresión regular Java, ¿devolver toda la fila?

I would like to get the whole row as my output. For example when i type kp1 I want the whole row CVBN.... returned.

begin abc
CVBN(r,t,t) + PPP(l,r) <-> ZEK(r!1).R(l!1,r) kp1,km1
TNBC(l,r) + SSR(r,t,t) <-> KPT(l,r!1).XXXX(l,r!1) kp2,km2
TLCX(l!+,(r,t,t)) + VV(l!+,r) <-> BB(l!+,r!1).R(l!+,r!1) kp3,km3
end abc

He probado lo siguiente:

Pattern pattern = Pattern.compile("kp1");
Matcher matcher = pattern.matcher(mytextFromAbove);

// Find all matches
while (matcher.find()) 
    // Get the matching string
    match = matcher.group();

This only returns the substring kp1. Any help is really appreciated.


preguntado el 28 de agosto de 11 a las 03:08

It surprises me that it returns anything at all. Unless the interface has changed significantly, it looks as if you're using your long text as the regular expression and searching for something it describes in the string "kp1". -

thanks..i corrected that...but still it does not work. -

1 Respuestas

Change your expression to ^.*kp1.*$

Respondido 28 ago 11, 07:08

You also should enable MULTILINE for your pattern: ... Pattern.compile("^.*kp1.*$", Pattern.MULTILINE); - Mark Peters

Why does he need multiline if he's matching one line? - MK.

@MK: if you don't specify multiline those anchors match start and end of input, not a line. - Mark Peters

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.