[英]How to account for special non ASCII characters in regex
我不知道這是否是問題,但我似乎無法得到這個匹配。
String [] seTab3_HighRes=null;
public Map<String, String> tab3HighResRegex(String x, Map<String,String> map) {
Pattern Tab3_HighRes_pattern = Pattern.compile("High Resolution Parameters:(.*?Intrabolus pressure)",Pattern.DOTALL);
Matcher matcherTab3_HighRes_pattern = Tab3_HighRes_pattern.matcher(x);
while (matcherTab3_HighRes_pattern.find()) {
System.out.println("Anything here? Nope");
seTab3_HighRes=matcherTab3_HighRes_pattern.group(1).split("\\n|\\r");
}
}
案文是:
High Resolution Parameters:
Intrabolus pressure (@LESR)(mmHg):-3.7 <8.4
Some other stff: 123
Intrabolus pressure (avg max)(mmHg):8.3 <17.0
我在文本中看了一下,注意到High Resolution Parameters:
末尾有一個^G
字符High Resolution Parameters:
當我將文本粘貼到textpad中時。 它是什么,是因為我沒有得到匹配(以及如何擺脫它?
你可以簡單地將^G
控制G與\\cG
,
這個正則表達式執行以下操作:
High Resolution Parameters:
Intrabolus pressure
Intrabolus pressure ... :
后拉出子串Intrabolus pressure ... :
正則表達式
High\sResolution\sParameters:(?:\cG|[\n\r\s])*(?:Intrabolus\spressure)[^:]*:([^\n]*)
https://regex101.com/r/pE5aI0/1
Intrabolus pressure
值 擴展
NODE EXPLANATION
----------------------------------------------------------------------
High 'High'
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
Resolution 'Resolution'
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
Parameters: 'Parameters:'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more times
(matching the most amount possible)):
----------------------------------------------------------------------
\cG ^G
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[\n\r\s] any character of: '\n' (newline), '\r'
(carriage return), whitespace (\n, \r,
\t, \f, and " ")
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
Intrabolus 'Intrabolus'
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
pressure 'pressure'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
[^:]* any character except: ':' (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[^\n]* any character except: '\n' (newline) (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.