I’m trying to exclude some data from a string using regex.
var match = Regex.Match(text, @"^(24 47(.*?)0D 0A)$");
The idea is to filter out and data starting with “24 47” and ending “0D 0A”
The source string:
A0 A1 00 02 83 00 83 0D 0A
A0 A1 00 02 84 1B 9F 0D 0A
24 47 50 47 47 41 2C 31 32 31 39 30 37 2E 30 30 30 2C 32 34 30 30 2E 30 30 30 30 2C 4E 2C 31 32 31 30 30 2E 30 30 30 30 2C 45 2C 30 2C 30 30 2C 30 2E 30 2C 30 2E 30 2C 4D 2C 30 2E 30 2C 4D 2C 2C 30 30 30 30 2A 36 35 0D 0A
24 47 50 47 53 41 2C 41 2C 31 2C 2C 2C 2C 2C 2C 2C 2C 2C 2C 2C 2C 2C 30 2E 30 2C 30 2E 30 2C 30 2E 30 2A 33 30 0D 0A
24 47 50 52 4D 43 2C 31 32 31 39 30 37 2E 30 30 30 2C 56 2C 32 34 30 30 2E 30 30 30 30 2C 4E 2C 31 32 31 30 30 2E 30 30 30 30 2C 45 2C 30 30 30 2E 30 2C 30 30 30 2E 30 2C 32 38 30 36 30 36 2C 2C 2C 4E 2A 37 34 0D 0A
24 47 50 56 54 47 2C 30 30 30 2E 30 2C 54 2C 2C 4D 2C 30 30 30 2E 30 2C 4E 2C 30 30 30 2E 30 2C 4B 2C 4E 2A 30 32 0D 0A
But I only want this:
A0 A1 00 02 83 00 83 0D 0A
A0 A1 00 02 84 1B 9F 0D 0A
Your regex requires the entire string to start with “24 47” and end with “0D 0A”. You want the multiline option that makes
^and$match start/end of each line:Try
If you want to exclude those lines, then use a negative lookahead:
If you want to find and remove delimited substrings anywhere in a long, contiguous string without line breaks, try this: