From e6dbb350a9def15fad3b3161749989f4c1ff88a4 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 12 Apr 2015 22:22:56 +0300 Subject: [PATCH] Update documentation --- src/nre.nim | 75 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/nre.nim b/src/nre.nim index b119ea739c..f5bb55045b 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -47,14 +47,7 @@ from unicode import runeLenAt type Regex* = ref object ## Represents the pattern that things are matched against, constructed with - ## ``re(string, string)``. Examples: ``re"foo"``, ``re(r"foo # comment", - ## "x")``, ``re"(?x)(*ANYCRLF)foo # comment"``. For more details - ## on the leading option groups, see the `Option - ## Setting `__ - ## and the `Newline - ## Convention `__ - ## sections of the `PCRE syntax - ## manual `__. + ## ``re(string)``. Examples: ``re"foo"``, ``re(r"(*ANYCRLF)(?x)foo # comment". ## ## ``pattern: string`` ## the string that was used to create the pattern. @@ -66,33 +59,36 @@ type ## a table from the capture names to their numeric id. ## ## - ## Flags - ## ..... + ## Options + ## ....... ## - ## - ``8``, ``u``, ```` - treat both the pattern and subject as UTF8 - ## - ``9``, ```` - prevents the pattern from being interpreted as UTF, no matter - ## what - ## - ``A``, ```` - as if the pattern had a ``^`` at the beginning - ## - ``E``, ```` - DOLLAR\_ENDONLY - ## - ``f``, ```` - fails if there is not a match on the first line - ## - ``i``, ```` - case insensitive - ## - ``m``, ```` - multi-line, ``^`` and ``$`` match the beginning and end of + ## The following options may appear anywhere in the pattern, and they affect + ## the rest of it. + ## + ## - ``(?i)`` - case insensitive + ## - ``(?m)`` - multi-line: ``^`` and ``$`` match the beginning and end of ## lines, not of the subject string - ## - ``N``, ```` - turn off auto-capture, ``(?foo)`` is necessary to capture. - ## - ``s``, ```` - ``.`` matches newline - ## - ``U``, ```` - expressions are not greedy by default. ``?`` can be added to - ## a qualifier to make it greedy. - ## - ``W``, ```` - Unicode character properties; ``\w`` matches ``к``. - ## - ``X``, ```` - "Extra", character escapes without special meaning (``\w`` - ## vs. ``\a``) are errors - ## - ``x``, ```` - extended, comments (``#``) and newlines are ignored - ## (extended) - ## - ``Y``, ```` - pcre.NO\_START\_OPTIMIZE, - ## - ```` - newlines are separated by ``\r`` - ## - ```` - newlines are separated by ``\r\n`` (Windows default) - ## - ```` - newlines are separated by ``\n`` (UNIX default) - ## - ```` - newlines are separated by any of the above - ## - ```` - newlines are separated by any of the above and Unicode + ## - ``(?s)`` - ``.`` also matches newline (*dotall*) + ## - ``(?U)`` - expressions are not greedy by default. ``?`` can be added + ## to a qualifier to make it greedy + ## - ``(?x)`` - whitespace and comments (``#``) are ignored (*extended*) + ## - ``(?X)`` - character escapes without special meaning (``\w`` vs. + ## ``\a``) are errors (*extra*) + ## + ## One or a combination of these options may appear only at the beginning + ## of the pattern: + ## + ## - ``(*UTF8)`` - treat both the pattern and subject as UTF-8 + ## - ``(*UCP)`` - Unicode character properties; ``\w`` matches ``я`` + ## - ``(*U)`` - a combination of the two options above + ## - ``(*FIRSTLINE*)`` - fails if there is not a match on the first line + ## - ``(*NO_AUTO_CAPTURE)`` - turn off auto-capture for groups; + ## ``(?...)`` can be used to capture + ## - ``(*CR)`` - newlines are separated by ``\r`` + ## - ``(*LF)`` - newlines are separated by ``\n`` (UNIX default) + ## - ``(*CRLF)`` - newlines are separated by ``\r\n`` (Windows default) + ## - ``(*ANYCRLF)`` - newlines are separated by any of the above + ## - ``(*ANY)`` - newlines are separated by any of the above and Unicode ## newlines: ## ## single characters VT (vertical tab, U+000B), FF (form feed, U+000C), @@ -101,10 +97,15 @@ type ## are recognized only in UTF-8 mode. ## — man pcre ## - ## - ```` - ``\R`` matches CR, LF, or CRLF - ## - ```` - ``\R`` matches any unicode newline - ## - ```` - Javascript compatibility - ## - ```` - turn off studying; study is enabled by deafault + ## - ``(*JAVASCRIPT_COMPAT)`` - JavaScript compatibility + ## - ``(*NO_STUDY)`` - turn off studying; study is enabled by default + ## + ## For more details on the leading option groups, see the `Option + ## Setting `__ + ## and the `Newline + ## Convention `__ + ## sections of the `PCRE syntax + ## manual `__. pattern*: string ## not nil pcreObj: ptr pcre.Pcre ## not nil pcreExtra: ptr pcre.ExtraData ## nil