RnD RnD - 1 year ago 88
Java Question

Regular expression Java, return the whole row?

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

I tried the following:

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.


Answer Source

Change your expression to ^.*kp1.*$

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download