简体   繁体   English

Java正则表达式,返回整行吗?

[英]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. 例如,当我键入kp1时,我希望返回整行CVBN....。

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 . 这仅返回子字符串kp1 Any help is really appreciated. 任何帮助都非常感谢。

Thanks. 谢谢。

将表达式更改为^.*kp1.*$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM