zrex(3)

zrex(3)

CZMQ Manual - CZMQ/2.2.1

Name

zrex - work with regular expressions

Synopsis

//  Constructor. Optionally, sets an expression against which we can match
//  text and capture hits. If there is an error in the expression, reports
//  zrex_valid() as false and provides the error in zrex_strerror(). If you
//  set a pattern, you can call zrex_hits() to test it against text.
CZMQ_EXPORT zrex_t *
    zrex_new (const char *expression);

//  Destructor
CZMQ_EXPORT void
    zrex_destroy (zrex_t **self_p);

//  Return true if the expression was valid and compiled without errors.
CZMQ_EXPORT bool
    zrex_valid (zrex_t *self);

//  Return the error message generated during compilation of the expression.
CZMQ_EXPORT const char *
    zrex_strerror (zrex_t *self);

//  Matches the text against a previously set expression, and reports the
//  number of hits (aka "capture groups" in e.g. Perl). If the text does
//  not match, returns 0. If it matches, returns 1 or greater, depending on
//  how many "(...)" groups the expression has. An expression with one group
//  will produce 2 hits, one for the whole expression and one for the group.
//  To retrieve the individual hits, call zrex_hit ().
CZMQ_EXPORT int
    zrex_hits (zrex_t *self, const char *text);

//  Matches the text against a new expression, and reports the number of
//  hits. If the text does not match, returns 0. If it matches, returns 1 or
//  greater, depending on how many "(...)" groups the expression has. An
//  expression with one group will produce 2 hits, one for the whole
//  expression and one for the group. To retrieve the individual hits, call
//  zrex_hit ().
CZMQ_EXPORT int
    zrex_eq (zrex_t *self, const char *text, const char *expression);

//  Returns the Nth sequence captured from the last expression match, where
//  N is 0 to the value returned by zrex_hits() or zrex_eq(). Sequence 0
//  is always the whole matching string. Sequence 1 is the first capture
//  group, if any, and so on.
CZMQ_EXPORT const char *
    zrex_hit (zrex_t *self, uint index);

//  Self test of this class
CZMQ_EXPORT int
    zrex_test (bool verbose);

Description

The zrex class provides a simple API for regular expressions, wrapping Alberto Demichelis's T-Rex library from http://tiny-rex.sourceforge.net/.

The underlying TRex class implements the following expressions:

\ Quote the next metacharacter ^ Match the beginning of the string . Match any character $ Match the end of the string | Alternation () Grouping (captures a hit) [] Character class

==GREEDY CLOSURES== * Match 0 or more times + Match 1 or more times ? Match 1 or 0 times {n,} Match at least n times {n,m} Match at least n but not more than m times

==ESCAPE CHARACTERS== \t tab (HT, TAB) \n newline (LF, NL) \r return (CR) \f form feed (FF)

==PREDEFINED CLASSES== \l lowercase next char \u uppercase next char \a alpha [a-zA-Z] \w alphanumeric [0-9a-zA-Z] \s space characters \d decimal digits \x hexadecimal digits \c control characters \p punctuation \b word boundary \A non letters \W non alphanumeric \S non space \D non decimal digits \X non hexadecimal digits \C non control characters \P non punctuation \B non word boundary

Example

From zrex_test method

See also

czmq(7)

Authors

The CZMQ manual was written by Pieter Hintjens<moc.xitami|hp#moc.xitami|hp>.

Resources

Main web site: http://czmq.zeromq.org/

Report bugs to the ØMQ development mailing list: <gro.qmorez.stsil|ved-qmorez#gro.qmorez.stsil|ved-qmorez>

Copyright

Copyright (c) 1991-2014 iMatix and Contributors. License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to change it and redistribute it. There is NO WARRANTY, to the extent permitted by law. For details see the files COPYING and COPYING.LESSER included with the CZMQ distribution.