[英]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.