I have a buffer that I am trying to parse using regular expressions.
Here is an example buffer:
DATA#ALPHAONE;BETATWO.CHARLIETHREE!
Format: The buffer always starts with "DATA #" as an alphabetic header. After that, it will have one or more text fields separated by a semicolon, period, or exclamation point.
My Regex pattern (in C #) so far:
string singleFieldPattern = "(?'Field'.*?)(?'Separator'[;.!])"; string fullBufferPattern = "(?'Header'DATA#)(" + singleFieldPattern + ")+";
The problem occurs when I try to flush data that matches:
Regex response = new Regex(fullBufferPattern); string example = "DATA#ALPHAONE;BETATWO.CHARLIETHREE!"; Debug.WriteLine("RegEx Matches?: {0}", response.IsMatch(example)); foreach (Match m in response.Matches(example)) { foreach(string s in new string[]{"Header", "Field", "Separator"}) { Debug.WriteLine("{0} : {1}", s, m.Groups[s]); } }
The only way out:
RegEx Matches?: True Header : DATA
I selected the following output:
RegEx Matches?: True Header : DATA
My expression did not receive the earlier ALPHAONE and BETATWO (and their delimiters ; and . ), As I expected. He only captured the last field ( CHARLIETHREE ).
How can I get all parts that match singleFieldPattern ?
I have simplified the data format above for questions, but since some people want real data, here is much closer to the actual data:
(Note: the values ββin [] are single bytes that are not printable, and spaces for clarity.)
Example:
[SYN] % SYSNAMScanner[ACK]; BAUDRATE57600[ACK]; CTRLMODEXON[ACK];
Transfer:
System Name (SYSNAM) - "Scanner"
Baud rate is 57,600 people Flow Control - XON