[英]Regular expression : remove words and number
我有一个字符串,我想删除字符串Input! + word + digits
Input! + word + digits
和Calc! + word + digits
Calc! + word + digits
。 我也尝试过。
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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.