我有一个字符串,我想删除该字符串输入! + 单词 + 数字
和计算! + 单词 + 数字
。我也包括了我的尝试。
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/