Licence of the PCRE library =========================== PCRE is a library of functions to support regular expressions whose syntax and semantics are as close as possible to those of the Perl 5 language. | Written by Philip Hazel | Copyright (c) 1997-2005 University of Cambridge ---------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of Cambridge nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Regular expression syntax and semantics ======================================= As the regular expressions supported by this module are enormous, the reader is referred to http://perldoc.perl.org/perlre.html for the full documentation of Perl's regular expressions. Because the backslash ``\`` is a meta character both in the Nim programming language and in regular expressions, it is strongly recommended that one uses the *raw* strings of Nim, so that backslashes are interpreted by the regular expression engine:: r"\S" # matches any character that is not whitespace A regular expression is a pattern that is matched against a subject string from left to right. Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern:: The quick brown fox matches a portion of a subject string that is identical to itself. The power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of metacharacters, which do not stand for themselves but instead are interpreted in some special way. There are two different sets of metacharacters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Outside square brackets, the metacharacters are as follows: ============== ============================================================ meta character meaning ============== ============================================================ ``\`` general escape character with several uses ``^`` assert start of string (or line, in multiline mode) ``$`` assert end of string (or line, in multiline mode) ``.`` match any character except newline (by def
discard """
  targets: "c js"
  matrix: "; -d:nimTestTpreludeCase1"
"""

when defined nimTestTpreludeCase1:
  include std/prelude
else:
  include prelude

template main() =
  doAssert toSeq(1..3) == @[1,2,3]
static: main()
main()
pair. These character type sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match. For compatibility with Perl, ``\s`` does not match the VT character (code 11). This makes it different from the the POSIX "space" class. The ``\s`` characters are HT (9), LF (10), FF (12), CR (13), and space (32). A "word" character is an underscore or any character less than 256 that is a letter or digit. The definition of letters and digits is controlled by PCRE's low-valued character tables, and may vary if locale-specific matching is taking place (see "Locale support" in the pcreapi page). For example, in the "fr_FR" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by ``\w``. In UTF-8 mode, characters with values greater than 128 never match ``\d``, ``\s``, or ``\w``, and always match ``\D``, ``\S``, and ``\W``. This is true even when Unicode character property support is available. Simple assertions ----------------- The fourth use of backslash is for certain `simple assertions`:idx:. An assertion specifies a condition that has to be met at a particular point in a match, without consuming any characters from the subject string. The use of subpatterns for more complicated assertions is described below. The backslashed assertions are:: ============== ============================================================ assertion meaning ============== ============================================================ ``\b`` matches at a word boundary ``\B`` matches when not at a word boundary ``\A`` matches at start of subject ``\Z`` matches at end of subject or before newline at end ``\z`` matches at end of subject ``\G`` matches at first matching position in subject ============== ============================================================ These assertions may not appear in character classes (but note that ``\b`` has a different meaning, namely the backspace character, inside a character class). A word boundary is a position in the subject string where the current character and the previous character do not both match ``\w`` or ``\W`` (i.e. one matches ``\w`` and the other matches ``\W``), or the start or end of the string if the first or last character matches ``\w``, respectively. The ``\A``, ``\Z``, and ``\z`` assertions differ from the traditional circumflex and dollar in that they only ever match at the very start and end of the subject string, whatever options are set. The difference between ``\Z`` and ``\z`` is that ``\Z`` matches before a newline that is the last character of the string as well as at the end of the string, whereas ``\z`` matches only at the end.