#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?im)(?:^(R)\|(\d+)\|\^*([^|]*)\|([^|]*)\|(?:([^|]*)\|)?.*$)|(?:^(P)\|(\d+)\|\|(\d+).*$)"
Local $sString = "P|1||322061||^|||U " & @CRLF & _
"O|1||138||||||||||||O " & @CRLF & _
"R|1|^^^BE(B)||mmol/L||C||||||20150819144937 " & @CRLF & _
"R|2|^^^BEecf||mmol/L||C " & @CRLF & _
"R|3|^^^Ca++|1.17|mmol/L " & @CRLF & _
"R|4|^^^Ca++(7.4)||mmol/L||C " & @CRLF & _
"R|5|^^^HCO23-||mmol/L||C " & @CRLF & _
"R|6|^^^HCO3std||mmol/L||C " & @CRLF & _
"R|7|^^^K+|5.0|mmol/L " & @CRLF & _
"R|8|^^^Na+|140|mmol/L " & @CRLF & _
"R|9|^^^SO2c||%||C " & @CRLF & _
"R|10|^^^TCO2||mmol/L||C " & @CRLF & _
"R|11|^^^THbc||g/dL||C " & @CRLF & _
"R|12|^^^Temp|37.0|C" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm