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

Re: [Libevent-users] libevhtp regex question



It could be that the first regex is matching before the third.  Perhaps ordering the expressions from most specific to least would allow it to match.  Also consider a terminating $ if there isn't supposed to be anything after in the url.  

--Bruce


On Sat, Nov 9, 2013 at 2:30 PM, Tom Pusateri <pusateri@xxxxxxxxx> wrote:
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