I have quite long strings, which are response from IMAP request, and I want to extract some values from it. It’s usually formatted like “x someword” or “someword x” – how get x (it can be more than one digit) for someword (which is known) ? Each “line” of response looks like:
* x someword \r\n
and my string contain a couple of this lines. What’s the simplest way to extract desired values?
Example:
for “* x word1\r\n* y word2\r\n”, with word2 as a parameter I want to get y
Whole response example:
* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)\r\n* OK [PERMANENTFLAGS ()] Flags permitted.\r\n* OK [UIDVALIDITY xxx] UIDs valid.\r\n* 3 EXISTS\r\n* 0 RECENT\r\n* OK [UIDNEXT x] Predicted next UID.\r\n. OK [READ-ONLY] INBOX selected. (Success)\r\n
For “EXISTS” I want to get 3.
I would use Regular Expressions… here’s what you can do: