text: PCREPATTERN(3) PCREPATTERN(3)
  NAMEPCRE - Perl-compatible regular expressions
  PCRE REGULAR EXPRESSION DETAILST) in order to provide some compatibility with regular expressions in Python, .NET, and Onigur A number of options that can be passed to pcre together right at the start of the pattern string, and the letters must be in upper case. UTF support appropri- ate Another special sequence that may appear at the start of a pattern is (*UCP). This has the same effect as setting the PCRE_UCP option: it causes sequences such as \d and \w to use Unicode properties to deter- mine character types, instead of recognizing only characters with codes less than 128 via a lookup table. Disabling auto-possessification If PCRE supports five different conventions for indicating line breaks in strings: a single CR (carriage return) character, a single LF (line- feed) character, the two-character sequence CRLF, any of the three pre- ceding, pat- tern string with one of the following five sequences: (*CR) carriage return (*LF) linefeed (*CRLF) carriage return, followed by linefeed (*ANYCRLF) any of the three above (*ANY) all Unicode newline sequences These override the default and the options given to the compiling func- tion. For example, on a Unix system where LF is the default newline sequence,_DOTALL is not set, and the behaviour of \N. However, it does not affect what the \R escape sequence matches. By default, this is any Unicode newline sequence, for Perl compatibility. However, this can be changed; see the description of \R in the section entitled "New- line sequences" below. A change of \R setting can be combined with a change of newline convention. Setting match and recursion limits The caller of pcre_exec() can set a limit on the number of times the internal match() function is called and on the maximum depth of recur- sive set- ting ASCII or Unicode (typically a mainframe sys- tem). In the sections below, character code values are ASCII or Uni- code; in an EBCDIC environment these characters may have different code values, and there are no code points greater than 255.
  CHARACTERS AND METACHARACTERSA PCRE_CASELESS option), letters are matched independently of case. In a UTF mode, PCRE always understands the concept of case for characters whose values are less than 128, so caseless matching is always possible. For characters with higher val- ues, recog- nizedThe- slash, you write \\.-JavaScript mode) \uhhhh character with hex code hhhh (JavaScript mode only). It is, however, recognized when PCRE is compiled in EBCDIC mode, where data items are always bytes. In this mode, all values are valid after \c. If the next character is a lower case letter, it is converted to upper case. Then the 0xc0 bits of the byte are inverted. Thus \cA becomes hex 01, as in ASCII (A is C1), but because the EBCDIC letters are disjoint, \cZ becomes hex 29 (Z is E9), and other characters also generate different values. less than following \ is greater than 7 and there have not been that many capturing subpatterns, PCRE handles \8 and \9 as the literal characters "8" and "9", and oth- erwise. If the PCRE_JAVASCRIPT_COMPAT option is set, the interpretation of \x is as just described only when it is followed by two hexadecimal dig- its. differ- ence in the way they are handled. For example, \xdc is exactly the same as \x{dc} (or \u00dc in JavaScript mode). Constraints on character values Characters" by default, but cause an error if the PCRE_EXTRA option is set. Outside a character class, these sequences have different meanings. Unsupported escape sequences. char- acter. This is the same as the "." metacharacter when PCRE_DOTALL is not set. Perl also uses \N to match characters by name; PCRE does not support this. Each pair of lower and upper case escape sequences partitions the com- plete vary for characters in the range 128-255 when locale-specific matching is happening. These escape sequences retain their original meanings from before Unicode support was available, mainly for efficiency rea- sons. If PCRE is compiled with Unicode property support, and the PCRE_UCP option is set, the behaviour is changed so that Unicode prop- erties_UCP is set. The horizontal space char- acters 8-bit (car- riage return, U+000D), or NEL (next line, U+0085). The two-character sequence is treated as a single unit that cannot be split. In other modes, two additional characters whose codepoints are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa- r func- tion,16), (*UTF32), (*UTF) or (*UCP) special sequences. Inside a character class, \R is treated as an unrecognized escape sequence, and so matches the letter "R" by default, but causes an error if PCRE_EXTRA is set. Unicode character properties When PCRE is built with Unicode character property support, three addi- tionalMu- sira- gana, Imperial_Aramaic, Inherited, Inscriptional_Pahlavi, Inscrip- tionalari- tan,, spec- ified by a two-letter abbreviation. For compatibility with Perl, nega- tion, unless UTF validity checking has been turned off (see the discussion of PCRE_NO_UTF8_CHECK, PCRE_NO_UTF16_CHECK and PCRE_NO_UTF32_CHECK in the pcreapi page).) prop- erty. prop- erty. That is why the traditional escape sequences such as \d and \w do not use Unicode properties in PCRE by default, though you can make them do so by setting the PCRE ear- lier, char- acter. sup- ports four more that make it possible to convert traditional escape sequences such as \w and \s to use Unicode properties. PCRE uses these non-standard, non-Perl properties internally when PCRE_UCP is set. How- ever, they may also be used explicitly. These properties are: Xan Any alphanumeric character Xps Any POSIX space character Xsp Any Perl space character Xwd Any Perl "word" character ver- tical tab, for Perl compatibility, but Perl changed, and so PCRE fol- lowed at release 8.34. Xwd matches the same characters as Xan, plus underscore. There is another non-standard property, Xuc, which matches any charac- ter char- acters asser- tion). However, if the PCRE_EXTRA option is set, an "invalid escape sequence" error is gener- ated instead. PCRE_UCP option. When this is done, it also affects \b and \B. Neither PCRE nor Perl has a separate "start of word" or "end of word" metase- qu the PCRE_NOTBOL or PCRE_NOTEOL options, which affect only the behaviour of the circumflex and dollar metacharacters. However, if the startoffset argument of pcre_exec() is non-zero, indi- cating argu- ments, you can mimic Perl's /g option, and it is in this kind of imple- mentation DOLLART. Dol- lar. FULL STOP (PERIOD, DOT) AND \N Outside a character class, a dot in the pattern matches any one charac- ter in the subject string except (by default) a character that signi- fies Uni- code- flexOutside a character class, the escape sequence \C matches any one data unit, whether or not a UTF mode is set. In the 8-bit library, one dataAn opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not spe- cial (UTF-16, UTF-32) charac- ters charac- ter, or z. It is not possible to have the literal character "]" as the end charac- ter inter- preted as a class containing a range followed by two other characters. The octal or hexadecimal representation of "]" can also be used to end a range. An error is generated if a POSIX character class (see below) or an escapeci- mal digit. In UTF modes, the PCRE" by default, but cause an error if the PCRE_EXTRA option is set., or for a special compatibility feature - see the next two sections), and the terminating closing square bracket. However, escaping other non- alphanumeric characters does no harm.
  POSIX CHARACTER CLASSESPerl and space space white space (the same as \s from PCRE 8.34) upper upper case, characters with values greater than 128 do not match any of the POSIX character classes. However, if the PCRE_UCP option is passed to pcre_compile(), some of the classes are changed so that Unicode character properties char- actersua- tion) property, plus those characters whose code points are less than 128 that have the S (Symbol) property. The other POSIX classes are unchanged, and match only characters with code points less than 128.
  COMPATIBILITY FEATURE FOR WORD BOUNDARIES assertions that are used above in order to give exactly the POSIX be- haviour.
  VERTICAL BARThe possi- ble to unset these options by preceding the letter with a hyphen, and a combined setting and unsetting such as (?im-sx), which sets PCRE_CASE- LESS (and it will there- fore show up in data extracted by the pcre_fullinfo() function). An option change within a subpattern (see below for a description of subpatterns)), (*UTF16),(*UTF32), and (*UCP) leading sequences that can be used to set UTF and Unicode prop- erty modes; they are equivalent to setting the PCRE_UTF8, PCRE_UTF16, PCRE_UTF32 and the PCRE_UCP options, respectively. The (*UTF) sequence is a generic version that can be used with any of the libraries. How- ever, the application can set the PCRE_NEVER_UTF option, which locks out the use of the (*UTF) sequences.
  SUBPATTERNSSub whole pattern matches, that portion of the subject string that matched the subpattern is passed back to the caller via the ovector argument of the matching function. (This applies only to the traditional matching functions; the DFA matching functions do not sup- port capturing.) num- bered captur- ing,Perl cap- turing parentheses are numbered one. Thus, when the pattern matches, you can look at captured substring number one, whichever alternative matched. This construct is useful when you want to capture part, but not all, of one of a number of alternatives. Inside a (?| group, paren- theses are numbered as usual, but the number is reset at the start of each branch. The numbers of any capturing parentheses that follow the subpattern start after the highest number used in any branch. The fol- lowing example is taken from the Perl documentation. The numbers under- neath num- ber have matched. An alternative approach to using this "branch reset" feature is to use duplicate named subpatterns, as described in the next section.
  NAMED SUBPATTERNSIdentifying., but must start with a non-digit..) Dupli- cate pat- tern always give the same name to subpatterns with the same number, even when PCRE_DUPNAMES is not set.
  REPETITIONRepetition exam- ple, {,6} is not a quantifier, but a literal string of four characters. In UTF modes, quantifiers apply to characters rather than to individual data units. Thus, for example, \x{100}{2} matches two characters, each of which is represented by a two-byte sequence in a UTF-8 string. Simi- larly,  use- ful-charac- ter bro- ken. (equiv- alent- lines, it is worth setting PCRE_DOTALL in order to obtain this opti- mization, charac- ter. For this reason, such a pattern is not implicitly anchored. Another case where implicit anchoring is not applied is when the lead- ing .* is inside an atomic group. Once again, a match at the start may fail where a later one succeeds. Consider this itera- tions. For example, after /(a|(b))+/ matches "aba" the value of the second captured substring is "b".
  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERSWith con- tains sim- ple charac- ter that is required for a match, and fail early if it is not present in the string.) If the pattern is changed so that it uses an atomic group, like this: ((?>\D+)|<\d+>)*[!?] sequences of non-digits cannot be broken, and failure happens quickly.
  BACK REFERENCESOutside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a back reference to a capturing sub-, (( by default. For example, the pattern (a|(bc))\2 always fails if it starts to match "a" rather than "bc". However, if the PCRE_JAVASCRIPT_COMPAT option is set at compile time, a back refer- ence to an unset value matches an empty string. Because there may be many capturing parentheses in a pattern, all dig- its following a backslash are taken as part of a potential back refer- ence A back reference that occurs inside the parentheses to which it refers fails when the subpattern is first used, so, for example, (a\1) never matches. However, such references can be useful inside repeated sub- patterns. For example, the pattern (a|b\1)+ matches any number of "a"s and also "aba", "ababbaa" etc. At each iter- ation carried out only for positive assertions. (Perl sometimes, but not always, does do capturing in nega- tive- iness semi- colon sev- eral, because it makes it impossible to calculate the length of the lookbe- hind." pre- ceded by six characters, the first of which are digits and the last three of which are not "999". For example, it doesn't match "123abc- foo".SIt is possible to cause the matching process to obey a subpattern there is more than one capturing subpattern with the same number (see the earlier section about duplicate subpattern numbers), the condition is true if any of them have matched. An alter- native or not the first set of parentheses matched. If they did, that is, if subject started with an opening parenthesis, the condition is true, and so the yes-pattern is executed and a closing parenthesis is required. Other- wise, refer- enced from elsewhere. (The use of subroutines is described below.) For example, a pattern to match an IPv4 address such as "192.168.23.245" could be written like this (ignore white space, insist- ing.
  COMMENTSThere are two ways of including comments in patterns that are processed by PCRE. In both cases, the start of the comment must not be in a char- acter class, nor the section entitled "Newline conventions" above. Note that the end of this type of comment is a literal newline sequence in the pattern; escape sequences that happen to represent a newline do not count. For example, consider this pattern when PCRE PATTERNSConsiderhe- sized refer- enced. pat- tern you want to obtain intermediate values, a callout function can be used (see below and the pcrecallout documenta- tion). brack- ets, allowing for arbitrary nesting. Only digits are allowed in nested brackets (that is, when recursing), whereas any characters are permit- tedin- dpat- tern alter- natives PCRE,If sub- ject string, it is never re-entered, even if it contains untried alter- natives and there is a subsequent matching failure. Any capturing parenthesesFor, rewrit- ten.
  CALLOUTSPerl provides a similar feature, but of course it cannot obey arbitrary Perl code. The feature is called "callout". The caller of PCRE provides an external function by putting its entry point in the global variable pcre_callout (8-bit library) or pcre[16|32]_callout (16-bit or 32-bit library). If the PCRE_AUTO_CALLOUT flag is passed to a compiling function, call- outs are automatically installed before each item in the pattern. They are all numbered 255. If there is a conditional group in the pattern whose condition is an assertion, an additional callout is inserted just before the condition. An explicit callout may also be set at this posi- tion, as in this example: (?(?C9)(?=a)abc|def) Note that this applies only to assertion conditions, not to other types of condition. During matching, when PCRE reaches a callout point, the external func- tion docu- mented PCRE_NO_START_OPTIMIZE option when calling pcre_com- pile() or pcre_exec(), or by starting the pattern with (*NO_START_OPT). There is more discussion of this option in the section entitled "Option bits for pcre_exec()" in the pcreapi documentation. pat- tern: out- putting. If you are interested in (*MARK) values after failed matches, you should probably set the PCRE_NO_START_OPTIMIZE option (see above) to ensure that the match is always attempted.track- pcre_exec() is committed to finding a match at the cur- rent pcretest example: re> /(*COMMIT)abc/ data> xyzabc 0: abc xyzabc\Y No match PCRE knows that any match must start with "a", so the optimization skips along the subject to "a" before running the first match attempt, which succeeds. When the optimization is disabled by the \Y escape in the second subject,track- ing quan- t). (*SKIP) This verb, when given without a name, is like (*PRUNE), except that if the pattern is unanchored, the "bumpalong" advance is not to the next character, but to the position in the subject where (*SKIP) was encoun- tered. ( quan- t- tracking subse- quently BAZ fails, there are no more alternatives, so there is a back- track pat- tern,.
  SEE ALSOpcreapi(3), pcrecallout(3), pcrematching(3), pcresyntax(3), pcre(3), pcre16(3), pcre32(3).
  AUTHORPhilip Hazel University Computing Service Cambridge CB2 3QH, England.
  REVISIONLast updated: 03 December 2013 Copyright (c) 1997-2013 University of Cambridge. PCRE 8.34 03 December 2013 PCREPATTERN(3)