[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] libevhtp regex question



I know that libevhtp isn't officially part of libevent yet but maybe someone on this list will have a good solution.

Say I want to match the following URIs:
/customers/
/customers/1/
/customers/1/transactions/
/customers/1/transactions/13/

If I add matching expressions such as:

evhtp_set_cb(htp, "/customers/", customers_cb, "customers");
evhtp_set_regex_cb(htp, "^/customers/([0-9]+)/", customer_cb, NULL);
evhtp_set_regex_cb(htp, "^/customers/([0-9]+)/transactions/", transactions_for_customer_cb, NULL);
evhtp_set_regex_cb(htp, "^/customers/([0-9]+)/transactions/([0-9]+)/", transaction_for_customer_cb, NULL);

I can match the first expression but not get to the second:

start = '1', end = '/transactions/13/

What is the best way to get to the 2nd expression '13'?

I can re-parse end but then I have multiple places where the code contains the same expression.

If you're familiar with Python regular expressions, there is m.group(1), m.group(2), etc to get each match.

Thanks,
Tom

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail