【发布时间】:2017-06-03 19:57:19
【问题描述】:
什么是 ASTM 标准协议字符串的正则表达式?
"P|1||123456||^|||U" + ProtocolASCII.LF
+ "O|1||138||||||||||||O" + ProtocolASCII.LF
+ "R|1|^^^BE(B)||mmol/L||C||||||20150819144937" + ProtocolASCII.LF
+ "R|2|^^^BEecf||mmol/L||C" + ProtocolASCII.LF
+ "R|3|^^^Ca++|1.17|mmol/L" + ProtocolASCII.LF
在哪里ProtocolASCII.LF = '\n'。我正在编写字符串 parser 来从这个字符串中提取数据。
我已经根据\n 拆分了字符串,现在我需要解析每个字符串以提取数据。
是否有任何正则表达式,以便我可以映射并获得所需的结果?
字符串P|1||123456||^|||U" + ProtocolASCII.LF 表示患者编号,其中P 表示患者标签或患者信息,123456 表示患者编号。
对于字符串R|3|^^^Ca++|1.17|mmol/L" + ProtocolASCII.LF 是执行实验室测试的结果。其中R表示结果,^^^Ca++表示结果名称,1.17表示结果值,mmol/L是单位。
目前我正在解析这样的字符串:
String[] resultArray = dataString.split("[\\r\\n]+");
HashMap<String, Object> resultData = new HashMap<>();
List<Result> sampleResults = new ArrayList<>();
for (String res : resultArray) {
//Get first character of String
char startChar = res.charAt(0);
switch (startChar) {
case ProtocolASCII.STX:
//Handle Header information. This is special case
if (res.charAt(2) == ProtocolASCII.Alphabet.H
|| res.charAt(1) == ProtocolASCII.Alphabet.H) {
resultData.put(Key.MACHINE_INFO, getHeaderInfo(res));
//System.out.println(res.charAt(2));
}
break;
case ProtocolASCII.Alphabet.P:
resultData.put(Key.PATIENT, getPatientInfo(res));
break;
case ProtocolASCII.Alphabet.O:
resultData.put(Key.ORDER, getOrderInfo(res));
break;
case ProtocolASCII.Alphabet.R:
sampleResults.add(getResultInfo(res));
break;
case ProtocolASCII.Alphabet.L:
// TODO - Handle end of line
break;
}
}
这是我完整的 ASTM 协议字符串:
/**
* Sample string
*/
public static final String MACHINE_STRING_ASTM = ProtocolASCII.STX + "1H|\\^&|||GEM 3000^5.6.1 ^21152^^023665^2.4|||||||||20150819154754" + ProtocolASCII.LF
+ "P|1||322061||^|||U" + ProtocolASCII.LF
+ "O|1||138||||||||||||O" + ProtocolASCII.LF
+ "R|1|^^^BE(B)||mmol/L||C||||||20150819144937" + ProtocolASCII.LF
+ "R|2|^^^BEecf||mmol/L||C" + ProtocolASCII.LF
+ "R|3|^^^Ca++|1.17|mmol/L" + ProtocolASCII.LF
+ "R|4|^^^Ca++(7.4)||mmol/L||C" + ProtocolASCII.LF
+ "R|5|^^^HCO23-||mmol/L||C" + ProtocolASCII.LF
+ "R|6|^^^HCO3std||mmol/L||C" + ProtocolASCII.LF
+ "R|7|^^^K+|5.0|mmol/L" + ProtocolASCII.LF
+ "R|8|^^^Na+|140|mmol/L" + ProtocolASCII.LF
+ "R|9|^^^SO2c||%||C" + ProtocolASCII.LF
+ "R|10|^^^TCO2||mmol/L||C" + ProtocolASCII.LF
+ "R|11|^^^THbc||g/dL||C" + ProtocolASCII.LF
+ "R|12|^^^Temp|37.0|C" + ProtocolASCII.LF
+ "L|1" + ProtocolASCII.EOT;
有没有一种方法可以使用Regular Expressions 提取数据?
如果需要更多信息,请告诉我。
谢谢
【问题讨论】:
-
给我们一个清晰的画面,当它分别以 P,R,O,L 开头时,你想从这些行中得到什么......然后可能不必了解 ASTM 协议,但给你一个解决方案...比如说,如果该行以 P 开头,您想为其余行解析什么,对于 R、O、L 也是如此
-
@Maverick_Mrt 我也提到了这个问题!如果它以R开头,我们需要获取除|之外的值,因为它是分隔符。例如,R|3|是化学成分Ca++的测试结果,其值为1.17,单位为mmol/L。所以,只要 R|n|来了,我需要提取这些数据。请注意,R|4|除了价值之外,拥有所有这些东西。
标签: java regex string pattern-matching