【发布时间】:2017-02-15 05:35:04
【问题描述】:
我是 Java 新手。我目前正在使用 Java 中的正则表达式 (regex)。 这是我的问题:我想删除:“基金经理:CI Investments Inc.”这部分通过我的正则表达式。我怎样才能做到? 我的代码部分如下所示。
CIG2306 /CIG3306 /CIG1306 基金经理:CI Investments Inc. 这是我读到的输出之一。我想为此输出专门添加一个正则表达式。因为我不希望从我的输出中删除部分基金经理:CI Investments Inc。
public class Main { String text; private getFundCode(){ Pattern ptnFundCode = Pattern.compile("Fund code\\w?:\\s*(.*)[\\r\\n]+", Pattern.CASE_INSENSITIVE); Matcher mchFundCode = ptnFundCode.matcher(text); if(mchFundCode.find()){ System.out.println(mchFundCode.group(1)); //tempResult+=mchFundCode.group(1)+"; "; } else{ tempResult+="N/A; "; }
【问题讨论】:
-
请显示您尝试过的代码。
-
你的代码示例在哪里
-
您是否需要使用正则表达式,或者字符串替换也可以?
-
public class Main { String text; private getFundCode(){ Pattern ptnFundCode = Pattern.compile("Fund code\\w?:\\s*(.*)[\\r\\n]+", Pattern.CASE_INSENSITIVE); Matcher mchFundCode = ptnFundCode.matcher(text); if(mchFundCode.find()){ System.out.println(mchFundCode.group(1)); //tempResult+=mchFundCode.group(1)+"; "; } else{ tempResult+="N/A; "; } -
请编辑您对此代码提出的问题