java - 正则表达式: remove words and number

标签 java regex

我有一个字符串,我想删除该字符串输入! + 单词 + 数字计算! + 单词 + 数字 。我也包括了我的尝试。

Input : IF(Input!B34 + Calc!B45)
Output : Input!B34 Calc!B45

我的尝试:

Pattern findMyPattern = Pattern.compile("Input!\\w\\d|" + worksheetName+ "!.+?");
        Matcher foundAMatch = findMyPattern.matcher(input);
        HashSet hashSet = new HashSet();
        while (foundAMatch.find()) {
            String s = foundAMatch.group(0);
            hashSet.add(s);
        }

我应该使用什么正则表达式?我尝试使用其中的一些。但我不是这方面的专家。一些想法会有用。

最佳答案

您可以使用此正则表达式:

"(?:Input|Calc)![a-zA-Z]\\d+"

说明:

(?:Input|Calc)  // Match `Input or Calc`
 !              // Followed by !
[a-zA-Z]        // Followed by an alphabetical character
\\d+            // Then digits.

并将其与 Matcher#find 一起使用,然后将 matcher.group() 添加到您的 Set 中。

关于java - 正则表达式: remove words and number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14861530/

相关文章:

java - 你会如何递归地编写这段代码?

javascript - 解析ffmpeg信息的正则表达式

java - 标注 Adempiere 中的确认(是/否)对话框

java - 修补 Glassfish 中的单个类

regex - 从区域文件中提取 IP 和指针记录

javascript - 检查文件名后缀是否为 .js

python - 在 Python 中使用正则表达式查找字符串中的多年经验

php - 如何检查一个字符串是否至少包含 5 个唯一字符且长度至少为 7 个字符?

java - 无法删除 Hudson 中的工作区

java - Tomcat : Application errors when multiple WARs deployed