Update README

parent 9b531d22
......@@ -24,9 +24,12 @@ SYNOPSIS
import re;
# object interface
new <obj> = re.regex(STRING, [, INT limit] [, INT limit_recursion])
new <obj> = re.regex(STRING, [, INT limit] [, INT limit_recursion]
[, BOOL forbody])
BOOL <obj>.match(STRING, [, INT limit] [, INT limit_recursion])
STRING <obj>.backref(INT [, STRING fallback])
BOOL <obj>.match_body(req_body | bereq_body | resp_body,
[, INT limit] [, INT limit_recursion])
# function interface
BOOL re.match_dyn(STRING, [, INT limit] [, INT limit_recursion])
......@@ -37,13 +40,17 @@ SYNOPSIS
DESCRIPTION
===========
.. _regsub(): https://varnish-cache.org/docs/trunk/reference/vcl.html#regsub-str-regex-sub
.. _regsuball(): https://varnish-cache.org/docs/trunk/reference/vcl.html#regsuball-str-regex-sub
Varnish Module (VMOD) for matching strings against regular expressions,
and for extracting captured substrings after matches.
Regular expression matching as implemented by the VMOD is equivalent
to VCL's infix operator ``~``. The VMOD is motivated by the fact that
backreference capture in standard VCL requires verbose and suboptimal
use of the ``regsub`` or ``regsuball`` functions. For example, this
use of the `regsub()`_ or `regsuball()`_ functions. For example, this
common idiom in VCL captures a string of digits following the
substring ``"bar"`` from one request header into another::
......@@ -73,18 +80,21 @@ The equivalent solution with the VMOD looks like this::
}
}
For an example on body matching, see `xregex.match_body()`_.
The object is created at VCL initialization with the regex containing
the capture expression, only describing the substring to be
matched. When a match with the ``match`` method succeeds, then a
captured string can be obtained from the ``backref`` method.
matched. When a match with the ``match`` or ``match_body`` method
succeeds, then a captured string can be obtained from the ``backref``
method.
Calls to the ``backref`` method refer back to the most recent
successful call to ``match`` for the same object in the same task
scope; that is, in the same client or backend context. For example if
``match`` is called for an object in one of the ``vcl_backend_*``
subroutines and returns ``true``, then subsequent calls to ``backref``
in the same backend scope extract substrings from the matched
substring.
successful call to ``match`` or ``match_body`` for the same object in
the same task scope; that is, in the same client or backend
context. For example if ``match`` is called for an object in one of
the ``vcl_backend_*`` subroutines and returns ``true``, then
subsequent calls to ``backref`` in the same backend scope extract
substrings from the matched substring.
The VMOD also supports dynamic regex matching with the ``match_dyn``
and ``backref_dyn`` functions::
......@@ -262,7 +272,7 @@ Description
scope (client or backend context), or a fallback string in
case the extraction fails. Backref 0 indicates the entire
matched string. Thus this function behaves like the ``\n``
symbols in ``regsub`` and ``regsuball``, and the ``$1``,
symbols in `regsub()`_ and `regsuball()`_, and the ``$1``,
``$2`` ... variables in Perl.
After unsuccessful matches, the ``fallback`` string is returned
......@@ -270,7 +280,7 @@ Description
is ``"**BACKREF METHOD FAILED**"``.
The VCL infix operators ``~`` and ``!~`` do not affect this
method, nor do the functions ``regsub`` or ``regsuball``.
method, nor do the functions `regsub()`_ or `regsuball()`_.
If ``backref`` is called without any prior call to ``match``
for this object in the same task scope, then an error message
......@@ -400,7 +410,7 @@ COPYRIGHT
::
Copyright 2014-2018 UPLEX Nils Goroll Systemoptimierung
Copyright 2014-2023 UPLEX Nils Goroll Systemoptimierung
All rights reserved
This document is licensed under the same conditions as the libvmod-re
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment