Reputation: 309
Suppose i have this string as input
char peer0_0[] = { 0x17, 0x03, 0x03, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xb3, 0xee, 0x9a, 0x37, 0xb6, 0xbf, 0x8f, 0x89, 0x58, 0xe4, 0x8d, 0x8a, 0x0b, 0xe8, 0x98, 0xba, 0x49, 0x0f, 0x45, 0x7c, 0x93, 0x65, 0x7b, 0x15, 0x78, 0xde, 0xe2, 0x9b, 0xd2, 0x9b, 0x26, 0x27, 0x4f, 0x3d, 0x1f, 0xf4, 0x4e, 0x0e, 0xcf, 0xa8, 0x60, 0xed, 0x45, 0x2f, 0x63, 0xeb, 0x4e, 0xcc, 0x55, 0x6f, 0x2f, 0x57, 0x0e, 0x7b, 0x7f, 0xd1, 0xcb, 0xc9, 0x87, 0x06, 0x9f, 0x81, 0x8e, 0x37, 0x80, 0xf2, 0x9f, 0xa0, 0xa4, 0x06, 0x75, 0x06, 0x45, 0x4c, 0x21, 0x51, 0x1a, 0x6a, 0x4b, 0x26, 0x9c, 0xdf, 0xee, 0xbc, 0x03, 0xee, 0x31, 0xa7, 0x2a, 0x46, 0xea, 0x91, 0x91, 0x6b, 0x6f, 0xc1, 0xa6, 0xf7, 0x3e, 0x16, 0x98, 0x63, 0x67, 0x86, 0x2f, 0xfb, 0x14, 0x8e, 0xd6, 0xcd, 0x14, 0x2c, 0xf7, 0xbf, 0x91, 0x18, 0x89, 0xaf, 0xad, 0xdf, 0x09, 0x2e, 0xc0, 0x20, 0x1c, 0x27, 0xf9, 0xba, 0xf4, 0xc7, 0xf2, 0x7e, 0x0d, 0x1d, 0x64, 0x4b, 0x85, 0x7e, 0xd7, 0x0f, 0xeb, 0x24, 0x2f, 0x3a, 0x61, 0x3d, 0x5e, 0x65, 0x75, 0x81, 0x34, 0xf6, 0x00, 0x2c };
And i want to extract the substring that is between {
and }
Of course i can scan the string until i detect {
and then until i detect }
and then doing substring between those indexes but there must be an easier way.
how can i do it? i thought i might need to use regular expressions but i couldn't make a suitable one.
Note:the string input might contain more examples as this,i mean after the };
in the Q input stream there will be char peer0_1[]={...
and so on
if you wonder where this input is coming from it's a stream content form wireshark
Upvotes: 1
Views: 263
Reputation: 46841
I want to extract the substring that is between { and }
Try below regex and get the matched group from index 1.
{([^}]*)
Explanation:
NODE EXPLANATION
--------------------------------------------------------------------------------
{ '{'
( group and capture to \1:
[^}]* any character except: '}' (0 or more
times (matching the most amount
possible))
) end of \1
The below regex will also return same result as suggested by @zx81 in comments without using capturing groups.
(?<={)[^}]*
Upvotes: 3