gpt4 book ai didi

java - 如何考虑正则表达式中的特殊非 ASCII 字符

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:15 24 4
gpt4 key购买 nike

我不知道这是否是问题所在,但我似乎无法使其匹配。

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

我仔细查看了文本,发现当我将文本粘贴到文本板时,高分辨率参数: 末尾有一个 ^G 字符。这是什么?这就是我没有获得匹配的原因(以及如何摆脱它?

最佳答案

描述

您可以简单地将 ^G 控件 G 与 \cG 匹配,

此正则表达式执行以下操作:

  • 匹配高分辨率参数:
  • 找到第一个注入(inject)内压力
  • 推注压力后拉出子字符串...:

正则表达式

High\sResolution\sParameters:(?:\cG|[\n\r\s])*(?:Intrabolus\spressure)[^:]*:([^\n]*)

Regular expression visualization

示例

https://regex101.com/r/pE5aI0/1

说明

  • 捕获组 0 获取整个字符串
  • 捕获组 1 获取推注内压力

扩展

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

关于java - 如何考虑正则表达式中的特殊非 ASCII 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37089239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com