pcre2syntax.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <html>
  2. <head>
  3. <title>pcre2syntax specification</title>
  4. </head>
  5. <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
  6. <h1>pcre2syntax man page</h1>
  7. <p>
  8. Return to the <a href="index.html">PCRE2 index page</a>.
  9. </p>
  10. <p>
  11. This page is part of the PCRE2 HTML documentation. It was generated
  12. automatically from the original man page. If there is any nonsense in it,
  13. please consult the man page, in case the conversion went wrong.
  14. <br>
  15. <ul>
  16. <li><a name="TOC1" href="#SEC1">PCRE2 REGULAR EXPRESSION SYNTAX SUMMARY</a>
  17. <li><a name="TOC2" href="#SEC2">QUOTING</a>
  18. <li><a name="TOC3" href="#SEC3">ESCAPED CHARACTERS</a>
  19. <li><a name="TOC4" href="#SEC4">CHARACTER TYPES</a>
  20. <li><a name="TOC5" href="#SEC5">GENERAL CATEGORY PROPERTIES FOR \p and \P</a>
  21. <li><a name="TOC6" href="#SEC6">PCRE2 SPECIAL CATEGORY PROPERTIES FOR \p and \P</a>
  22. <li><a name="TOC7" href="#SEC7">SCRIPT NAMES FOR \p AND \P</a>
  23. <li><a name="TOC8" href="#SEC8">CHARACTER CLASSES</a>
  24. <li><a name="TOC9" href="#SEC9">QUANTIFIERS</a>
  25. <li><a name="TOC10" href="#SEC10">ANCHORS AND SIMPLE ASSERTIONS</a>
  26. <li><a name="TOC11" href="#SEC11">REPORTED MATCH POINT SETTING</a>
  27. <li><a name="TOC12" href="#SEC12">ALTERNATION</a>
  28. <li><a name="TOC13" href="#SEC13">CAPTURING</a>
  29. <li><a name="TOC14" href="#SEC14">ATOMIC GROUPS</a>
  30. <li><a name="TOC15" href="#SEC15">COMMENT</a>
  31. <li><a name="TOC16" href="#SEC16">OPTION SETTING</a>
  32. <li><a name="TOC17" href="#SEC17">NEWLINE CONVENTION</a>
  33. <li><a name="TOC18" href="#SEC18">WHAT \R MATCHES</a>
  34. <li><a name="TOC19" href="#SEC19">LOOKAHEAD AND LOOKBEHIND ASSERTIONS</a>
  35. <li><a name="TOC20" href="#SEC20">NON-ATOMIC LOOKAROUND ASSERTIONS</a>
  36. <li><a name="TOC21" href="#SEC21">SCRIPT RUNS</a>
  37. <li><a name="TOC22" href="#SEC22">BACKREFERENCES</a>
  38. <li><a name="TOC23" href="#SEC23">SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)</a>
  39. <li><a name="TOC24" href="#SEC24">CONDITIONAL PATTERNS</a>
  40. <li><a name="TOC25" href="#SEC25">BACKTRACKING CONTROL</a>
  41. <li><a name="TOC26" href="#SEC26">CALLOUTS</a>
  42. <li><a name="TOC27" href="#SEC27">SEE ALSO</a>
  43. <li><a name="TOC28" href="#SEC28">AUTHOR</a>
  44. <li><a name="TOC29" href="#SEC29">REVISION</a>
  45. </ul>
  46. <br><a name="SEC1" href="#TOC1">PCRE2 REGULAR EXPRESSION SYNTAX SUMMARY</a><br>
  47. <P>
  48. The full syntax and semantics of the regular expressions that are supported by
  49. PCRE2 are described in the
  50. <a href="pcre2pattern.html"><b>pcre2pattern</b></a>
  51. documentation. This document contains a quick-reference summary of the syntax.
  52. </P>
  53. <br><a name="SEC2" href="#TOC1">QUOTING</a><br>
  54. <P>
  55. <pre>
  56. \x where x is non-alphanumeric is a literal x
  57. \Q...\E treat enclosed characters as literal
  58. </PRE>
  59. </P>
  60. <br><a name="SEC3" href="#TOC1">ESCAPED CHARACTERS</a><br>
  61. <P>
  62. This table applies to ASCII and Unicode environments. An unrecognized escape
  63. sequence causes an error.
  64. <pre>
  65. \a alarm, that is, the BEL character (hex 07)
  66. \cx "control-x", where x is any ASCII printing character
  67. \e escape (hex 1B)
  68. \f form feed (hex 0C)
  69. \n newline (hex 0A)
  70. \r carriage return (hex 0D)
  71. \t tab (hex 09)
  72. \0dd character with octal code 0dd
  73. \ddd character with octal code ddd, or backreference
  74. \o{ddd..} character with octal code ddd..
  75. \N{U+hh..} character with Unicode code point hh.. (Unicode mode only)
  76. \xhh character with hex code hh
  77. \x{hh..} character with hex code hh..
  78. </pre>
  79. If PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set ("ALT_BSUX mode"), the
  80. following are also recognized:
  81. <pre>
  82. \U the character "U"
  83. \uhhhh character with hex code hhhh
  84. \u{hh..} character with hex code hh.. but only for EXTRA_ALT_BSUX
  85. </pre>
  86. When \x is not followed by {, from zero to two hexadecimal digits are read,
  87. but in ALT_BSUX mode \x must be followed by two hexadecimal digits to be
  88. recognized as a hexadecimal escape; otherwise it matches a literal "x".
  89. Likewise, if \u (in ALT_BSUX mode) is not followed by four hexadecimal digits
  90. or (in EXTRA_ALT_BSUX mode) a sequence of hex digits in curly brackets, it
  91. matches a literal "u".
  92. </P>
  93. <P>
  94. Note that \0dd is always an octal code. The treatment of backslash followed by
  95. a non-zero digit is complicated; for details see the section
  96. <a href="pcre2pattern.html#digitsafterbackslash">"Non-printing characters"</a>
  97. in the
  98. <a href="pcre2pattern.html"><b>pcre2pattern</b></a>
  99. documentation, where details of escape processing in EBCDIC environments are
  100. also given. \N{U+hh..} is synonymous with \x{hh..} in PCRE2 but is not
  101. supported in EBCDIC environments. Note that \N not followed by an opening
  102. curly bracket has a different meaning (see below).
  103. </P>
  104. <br><a name="SEC4" href="#TOC1">CHARACTER TYPES</a><br>
  105. <P>
  106. <pre>
  107. . any character except newline;
  108. in dotall mode, any character whatsoever
  109. \C one code unit, even in UTF mode (best avoided)
  110. \d a decimal digit
  111. \D a character that is not a decimal digit
  112. \h a horizontal white space character
  113. \H a character that is not a horizontal white space character
  114. \N a character that is not a newline
  115. \p{<i>xx</i>} a character with the <i>xx</i> property
  116. \P{<i>xx</i>} a character without the <i>xx</i> property
  117. \R a newline sequence
  118. \s a white space character
  119. \S a character that is not a white space character
  120. \v a vertical white space character
  121. \V a character that is not a vertical white space character
  122. \w a "word" character
  123. \W a "non-word" character
  124. \X a Unicode extended grapheme cluster
  125. </pre>
  126. \C is dangerous because it may leave the current matching point in the middle
  127. of a UTF-8 or UTF-16 character. The application can lock out the use of \C by
  128. setting the PCRE2_NEVER_BACKSLASH_C option. It is also possible to build PCRE2
  129. with the use of \C permanently disabled.
  130. </P>
  131. <P>
  132. By default, \d, \s, and \w match only ASCII characters, even in UTF-8 mode
  133. or in the 16-bit and 32-bit libraries. However, if locale-specific matching is
  134. happening, \s and \w may also match characters with code points in the range
  135. 128-255. If the PCRE2_UCP option is set, the behaviour of these escape
  136. sequences is changed to use Unicode properties and they match many more
  137. characters.
  138. </P>
  139. <br><a name="SEC5" href="#TOC1">GENERAL CATEGORY PROPERTIES FOR \p and \P</a><br>
  140. <P>
  141. <pre>
  142. C Other
  143. Cc Control
  144. Cf Format
  145. Cn Unassigned
  146. Co Private use
  147. Cs Surrogate
  148. L Letter
  149. Ll Lower case letter
  150. Lm Modifier letter
  151. Lo Other letter
  152. Lt Title case letter
  153. Lu Upper case letter
  154. L& Ll, Lu, or Lt
  155. M Mark
  156. Mc Spacing mark
  157. Me Enclosing mark
  158. Mn Non-spacing mark
  159. N Number
  160. Nd Decimal number
  161. Nl Letter number
  162. No Other number
  163. P Punctuation
  164. Pc Connector punctuation
  165. Pd Dash punctuation
  166. Pe Close punctuation
  167. Pf Final punctuation
  168. Pi Initial punctuation
  169. Po Other punctuation
  170. Ps Open punctuation
  171. S Symbol
  172. Sc Currency symbol
  173. Sk Modifier symbol
  174. Sm Mathematical symbol
  175. So Other symbol
  176. Z Separator
  177. Zl Line separator
  178. Zp Paragraph separator
  179. Zs Space separator
  180. </PRE>
  181. </P>
  182. <br><a name="SEC6" href="#TOC1">PCRE2 SPECIAL CATEGORY PROPERTIES FOR \p and \P</a><br>
  183. <P>
  184. <pre>
  185. Xan Alphanumeric: union of properties L and N
  186. Xps POSIX space: property Z or tab, NL, VT, FF, CR
  187. Xsp Perl space: property Z or tab, NL, VT, FF, CR
  188. Xuc Univerally-named character: one that can be
  189. represented by a Universal Character Name
  190. Xwd Perl word: property Xan or underscore
  191. </pre>
  192. Perl and POSIX space are now the same. Perl added VT to its space character set
  193. at release 5.18.
  194. </P>
  195. <br><a name="SEC7" href="#TOC1">SCRIPT NAMES FOR \p AND \P</a><br>
  196. <P>
  197. Adlam,
  198. Ahom,
  199. Anatolian_Hieroglyphs,
  200. Arabic,
  201. Armenian,
  202. Avestan,
  203. Balinese,
  204. Bamum,
  205. Bassa_Vah,
  206. Batak,
  207. Bengali,
  208. Bhaiksuki,
  209. Bopomofo,
  210. Brahmi,
  211. Braille,
  212. Buginese,
  213. Buhid,
  214. Canadian_Aboriginal,
  215. Carian,
  216. Caucasian_Albanian,
  217. Chakma,
  218. Cham,
  219. Cherokee,
  220. Chorasmian,
  221. Common,
  222. Coptic,
  223. Cuneiform,
  224. Cypriot,
  225. Cyrillic,
  226. Deseret,
  227. Devanagari,
  228. Dives_Akuru,
  229. Dogra,
  230. Duployan,
  231. Egyptian_Hieroglyphs,
  232. Elbasan,
  233. Elymaic,
  234. Ethiopic,
  235. Georgian,
  236. Glagolitic,
  237. Gothic,
  238. Grantha,
  239. Greek,
  240. Gujarati,
  241. Gunjala_Gondi,
  242. Gurmukhi,
  243. Han,
  244. Hangul,
  245. Hanifi_Rohingya,
  246. Hanunoo,
  247. Hatran,
  248. Hebrew,
  249. Hiragana,
  250. Imperial_Aramaic,
  251. Inherited,
  252. Inscriptional_Pahlavi,
  253. Inscriptional_Parthian,
  254. Javanese,
  255. Kaithi,
  256. Kannada,
  257. Katakana,
  258. Kayah_Li,
  259. Kharoshthi,
  260. Khitan_Small_Script,
  261. Khmer,
  262. Khojki,
  263. Khudawadi,
  264. Lao,
  265. Latin,
  266. Lepcha,
  267. Limbu,
  268. Linear_A,
  269. Linear_B,
  270. Lisu,
  271. Lycian,
  272. Lydian,
  273. Mahajani,
  274. Makasar,
  275. Malayalam,
  276. Mandaic,
  277. Manichaean,
  278. Marchen,
  279. Masaram_Gondi,
  280. Medefaidrin,
  281. Meetei_Mayek,
  282. Mende_Kikakui,
  283. Meroitic_Cursive,
  284. Meroitic_Hieroglyphs,
  285. Miao,
  286. Modi,
  287. Mongolian,
  288. Mro,
  289. Multani,
  290. Myanmar,
  291. Nabataean,
  292. Nandinagari,
  293. New_Tai_Lue,
  294. Newa,
  295. Nko,
  296. Nushu,
  297. Nyakeng_Puachue_Hmong,
  298. Ogham,
  299. Ol_Chiki,
  300. Old_Hungarian,
  301. Old_Italic,
  302. Old_North_Arabian,
  303. Old_Permic,
  304. Old_Persian,
  305. Old_Sogdian,
  306. Old_South_Arabian,
  307. Old_Turkic,
  308. Oriya,
  309. Osage,
  310. Osmanya,
  311. Pahawh_Hmong,
  312. Palmyrene,
  313. Pau_Cin_Hau,
  314. Phags_Pa,
  315. Phoenician,
  316. Psalter_Pahlavi,
  317. Rejang,
  318. Runic,
  319. Samaritan,
  320. Saurashtra,
  321. Sharada,
  322. Shavian,
  323. Siddham,
  324. SignWriting,
  325. Sinhala,
  326. Sogdian,
  327. Sora_Sompeng,
  328. Soyombo,
  329. Sundanese,
  330. Syloti_Nagri,
  331. Syriac,
  332. Tagalog,
  333. Tagbanwa,
  334. Tai_Le,
  335. Tai_Tham,
  336. Tai_Viet,
  337. Takri,
  338. Tamil,
  339. Tangut,
  340. Telugu,
  341. Thaana,
  342. Thai,
  343. Tibetan,
  344. Tifinagh,
  345. Tirhuta,
  346. Ugaritic,
  347. Vai,
  348. Wancho,
  349. Warang_Citi,
  350. Yezidi,
  351. Yi,
  352. Zanabazar_Square.
  353. </P>
  354. <br><a name="SEC8" href="#TOC1">CHARACTER CLASSES</a><br>
  355. <P>
  356. <pre>
  357. [...] positive character class
  358. [^...] negative character class
  359. [x-y] range (can be used for hex characters)
  360. [[:xxx:]] positive POSIX named set
  361. [[:^xxx:]] negative POSIX named set
  362. alnum alphanumeric
  363. alpha alphabetic
  364. ascii 0-127
  365. blank space or tab
  366. cntrl control character
  367. digit decimal digit
  368. graph printing, excluding space
  369. lower lower case letter
  370. print printing, including space
  371. punct printing, excluding alphanumeric
  372. space white space
  373. upper upper case letter
  374. word same as \w
  375. xdigit hexadecimal digit
  376. </pre>
  377. In PCRE2, POSIX character set names recognize only ASCII characters by default,
  378. but some of them use Unicode properties if PCRE2_UCP is set. You can use
  379. \Q...\E inside a character class.
  380. </P>
  381. <br><a name="SEC9" href="#TOC1">QUANTIFIERS</a><br>
  382. <P>
  383. <pre>
  384. ? 0 or 1, greedy
  385. ?+ 0 or 1, possessive
  386. ?? 0 or 1, lazy
  387. * 0 or more, greedy
  388. *+ 0 or more, possessive
  389. *? 0 or more, lazy
  390. + 1 or more, greedy
  391. ++ 1 or more, possessive
  392. +? 1 or more, lazy
  393. {n} exactly n
  394. {n,m} at least n, no more than m, greedy
  395. {n,m}+ at least n, no more than m, possessive
  396. {n,m}? at least n, no more than m, lazy
  397. {n,} n or more, greedy
  398. {n,}+ n or more, possessive
  399. {n,}? n or more, lazy
  400. </PRE>
  401. </P>
  402. <br><a name="SEC10" href="#TOC1">ANCHORS AND SIMPLE ASSERTIONS</a><br>
  403. <P>
  404. <pre>
  405. \b word boundary
  406. \B not a word boundary
  407. ^ start of subject
  408. also after an internal newline in multiline mode
  409. (after any newline if PCRE2_ALT_CIRCUMFLEX is set)
  410. \A start of subject
  411. $ end of subject
  412. also before newline at end of subject
  413. also before internal newline in multiline mode
  414. \Z end of subject
  415. also before newline at end of subject
  416. \z end of subject
  417. \G first matching position in subject
  418. </PRE>
  419. </P>
  420. <br><a name="SEC11" href="#TOC1">REPORTED MATCH POINT SETTING</a><br>
  421. <P>
  422. <pre>
  423. \K set reported start of match
  424. </pre>
  425. \K is honoured in positive assertions, but ignored in negative ones.
  426. </P>
  427. <br><a name="SEC12" href="#TOC1">ALTERNATION</a><br>
  428. <P>
  429. <pre>
  430. expr|expr|expr...
  431. </PRE>
  432. </P>
  433. <br><a name="SEC13" href="#TOC1">CAPTURING</a><br>
  434. <P>
  435. <pre>
  436. (...) capture group
  437. (?&#60;name&#62;...) named capture group (Perl)
  438. (?'name'...) named capture group (Perl)
  439. (?P&#60;name&#62;...) named capture group (Python)
  440. (?:...) non-capture group
  441. (?|...) non-capture group; reset group numbers for
  442. capture groups in each alternative
  443. </pre>
  444. In non-UTF modes, names may contain underscores and ASCII letters and digits;
  445. in UTF modes, any Unicode letters and Unicode decimal digits are permitted. In
  446. both cases, a name must not start with a digit.
  447. </P>
  448. <br><a name="SEC14" href="#TOC1">ATOMIC GROUPS</a><br>
  449. <P>
  450. <pre>
  451. (?&#62;...) atomic non-capture group
  452. (*atomic:...) atomic non-capture group
  453. </PRE>
  454. </P>
  455. <br><a name="SEC15" href="#TOC1">COMMENT</a><br>
  456. <P>
  457. <pre>
  458. (?#....) comment (not nestable)
  459. </PRE>
  460. </P>
  461. <br><a name="SEC16" href="#TOC1">OPTION SETTING</a><br>
  462. <P>
  463. Changes of these options within a group are automatically cancelled at the end
  464. of the group.
  465. <pre>
  466. (?i) caseless
  467. (?J) allow duplicate named groups
  468. (?m) multiline
  469. (?n) no auto capture
  470. (?s) single line (dotall)
  471. (?U) default ungreedy (lazy)
  472. (?x) extended: ignore white space except in classes
  473. (?xx) as (?x) but also ignore space and tab in classes
  474. (?-...) unset option(s)
  475. (?^) unset imnsx options
  476. </pre>
  477. Unsetting x or xx unsets both. Several options may be set at once, and a
  478. mixture of setting and unsetting such as (?i-x) is allowed, but there may be
  479. only one hyphen. Setting (but no unsetting) is allowed after (?^ for example
  480. (?^in). An option setting may appear at the start of a non-capture group, for
  481. example (?i:...).
  482. </P>
  483. <P>
  484. The following are recognized only at the very start of a pattern or after one
  485. of the newline or \R options with similar syntax. More than one of them may
  486. appear. For the first three, d is a decimal number.
  487. <pre>
  488. (*LIMIT_DEPTH=d) set the backtracking limit to d
  489. (*LIMIT_HEAP=d) set the heap size limit to d * 1024 bytes
  490. (*LIMIT_MATCH=d) set the match limit to d
  491. (*NOTEMPTY) set PCRE2_NOTEMPTY when matching
  492. (*NOTEMPTY_ATSTART) set PCRE2_NOTEMPTY_ATSTART when matching
  493. (*NO_AUTO_POSSESS) no auto-possessification (PCRE2_NO_AUTO_POSSESS)
  494. (*NO_DOTSTAR_ANCHOR) no .* anchoring (PCRE2_NO_DOTSTAR_ANCHOR)
  495. (*NO_JIT) disable JIT optimization
  496. (*NO_START_OPT) no start-match optimization (PCRE2_NO_START_OPTIMIZE)
  497. (*UTF) set appropriate UTF mode for the library in use
  498. (*UCP) set PCRE2_UCP (use Unicode properties for \d etc)
  499. </pre>
  500. Note that LIMIT_DEPTH, LIMIT_HEAP, and LIMIT_MATCH can only reduce the value of
  501. the limits set by the caller of <b>pcre2_match()</b> or <b>pcre2_dfa_match()</b>,
  502. not increase them. LIMIT_RECURSION is an obsolete synonym for LIMIT_DEPTH. The
  503. application can lock out the use of (*UTF) and (*UCP) by setting the
  504. PCRE2_NEVER_UTF or PCRE2_NEVER_UCP options, respectively, at compile time.
  505. </P>
  506. <br><a name="SEC17" href="#TOC1">NEWLINE CONVENTION</a><br>
  507. <P>
  508. These are recognized only at the very start of the pattern or after option
  509. settings with a similar syntax.
  510. <pre>
  511. (*CR) carriage return only
  512. (*LF) linefeed only
  513. (*CRLF) carriage return followed by linefeed
  514. (*ANYCRLF) all three of the above
  515. (*ANY) any Unicode newline sequence
  516. (*NUL) the NUL character (binary zero)
  517. </PRE>
  518. </P>
  519. <br><a name="SEC18" href="#TOC1">WHAT \R MATCHES</a><br>
  520. <P>
  521. These are recognized only at the very start of the pattern or after option
  522. setting with a similar syntax.
  523. <pre>
  524. (*BSR_ANYCRLF) CR, LF, or CRLF
  525. (*BSR_UNICODE) any Unicode newline sequence
  526. </PRE>
  527. </P>
  528. <br><a name="SEC19" href="#TOC1">LOOKAHEAD AND LOOKBEHIND ASSERTIONS</a><br>
  529. <P>
  530. <pre>
  531. (?=...) )
  532. (*pla:...) ) positive lookahead
  533. (*positive_lookahead:...) )
  534. (?!...) )
  535. (*nla:...) ) negative lookahead
  536. (*negative_lookahead:...) )
  537. (?&#60;=...) )
  538. (*plb:...) ) positive lookbehind
  539. (*positive_lookbehind:...) )
  540. (?&#60;!...) )
  541. (*nlb:...) ) negative lookbehind
  542. (*negative_lookbehind:...) )
  543. </pre>
  544. Each top-level branch of a lookbehind must be of a fixed length.
  545. </P>
  546. <br><a name="SEC20" href="#TOC1">NON-ATOMIC LOOKAROUND ASSERTIONS</a><br>
  547. <P>
  548. These assertions are specific to PCRE2 and are not Perl-compatible.
  549. <pre>
  550. (?*...) )
  551. (*napla:...) ) synonyms
  552. (*non_atomic_positive_lookahead:...) )
  553. (?&#60;*...) )
  554. (*naplb:...) ) synonyms
  555. (*non_atomic_positive_lookbehind:...) )
  556. </PRE>
  557. </P>
  558. <br><a name="SEC21" href="#TOC1">SCRIPT RUNS</a><br>
  559. <P>
  560. <pre>
  561. (*script_run:...) ) script run, can be backtracked into
  562. (*sr:...) )
  563. (*atomic_script_run:...) ) atomic script run
  564. (*asr:...) )
  565. </PRE>
  566. </P>
  567. <br><a name="SEC22" href="#TOC1">BACKREFERENCES</a><br>
  568. <P>
  569. <pre>
  570. \n reference by number (can be ambiguous)
  571. \gn reference by number
  572. \g{n} reference by number
  573. \g+n relative reference by number (PCRE2 extension)
  574. \g-n relative reference by number
  575. \g{+n} relative reference by number (PCRE2 extension)
  576. \g{-n} relative reference by number
  577. \k&#60;name&#62; reference by name (Perl)
  578. \k'name' reference by name (Perl)
  579. \g{name} reference by name (Perl)
  580. \k{name} reference by name (.NET)
  581. (?P=name) reference by name (Python)
  582. </PRE>
  583. </P>
  584. <br><a name="SEC23" href="#TOC1">SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)</a><br>
  585. <P>
  586. <pre>
  587. (?R) recurse whole pattern
  588. (?n) call subroutine by absolute number
  589. (?+n) call subroutine by relative number
  590. (?-n) call subroutine by relative number
  591. (?&name) call subroutine by name (Perl)
  592. (?P&#62;name) call subroutine by name (Python)
  593. \g&#60;name&#62; call subroutine by name (Oniguruma)
  594. \g'name' call subroutine by name (Oniguruma)
  595. \g&#60;n&#62; call subroutine by absolute number (Oniguruma)
  596. \g'n' call subroutine by absolute number (Oniguruma)
  597. \g&#60;+n&#62; call subroutine by relative number (PCRE2 extension)
  598. \g'+n' call subroutine by relative number (PCRE2 extension)
  599. \g&#60;-n&#62; call subroutine by relative number (PCRE2 extension)
  600. \g'-n' call subroutine by relative number (PCRE2 extension)
  601. </PRE>
  602. </P>
  603. <br><a name="SEC24" href="#TOC1">CONDITIONAL PATTERNS</a><br>
  604. <P>
  605. <pre>
  606. (?(condition)yes-pattern)
  607. (?(condition)yes-pattern|no-pattern)
  608. (?(n) absolute reference condition
  609. (?(+n) relative reference condition
  610. (?(-n) relative reference condition
  611. (?(&#60;name&#62;) named reference condition (Perl)
  612. (?('name') named reference condition (Perl)
  613. (?(name) named reference condition (PCRE2, deprecated)
  614. (?(R) overall recursion condition
  615. (?(Rn) specific numbered group recursion condition
  616. (?(R&name) specific named group recursion condition
  617. (?(DEFINE) define groups for reference
  618. (?(VERSION[&#62;]=n.m) test PCRE2 version
  619. (?(assert) assertion condition
  620. </pre>
  621. Note the ambiguity of (?(R) and (?(Rn) which might be named reference
  622. conditions or recursion tests. Such a condition is interpreted as a reference
  623. condition if the relevant named group exists.
  624. </P>
  625. <br><a name="SEC25" href="#TOC1">BACKTRACKING CONTROL</a><br>
  626. <P>
  627. All backtracking control verbs may be in the form (*VERB:NAME). For (*MARK) the
  628. name is mandatory, for the others it is optional. (*SKIP) changes its behaviour
  629. if :NAME is present. The others just set a name for passing back to the caller,
  630. but this is not a name that (*SKIP) can see. The following act immediately they
  631. are reached:
  632. <pre>
  633. (*ACCEPT) force successful match
  634. (*FAIL) force backtrack; synonym (*F)
  635. (*MARK:NAME) set name to be passed back; synonym (*:NAME)
  636. </pre>
  637. The following act only when a subsequent match failure causes a backtrack to
  638. reach them. They all force a match failure, but they differ in what happens
  639. afterwards. Those that advance the start-of-match point do so only if the
  640. pattern is not anchored.
  641. <pre>
  642. (*COMMIT) overall failure, no advance of starting point
  643. (*PRUNE) advance to next starting character
  644. (*SKIP) advance to current matching position
  645. (*SKIP:NAME) advance to position corresponding to an earlier
  646. (*MARK:NAME); if not found, the (*SKIP) is ignored
  647. (*THEN) local failure, backtrack to next alternation
  648. </pre>
  649. The effect of one of these verbs in a group called as a subroutine is confined
  650. to the subroutine call.
  651. </P>
  652. <br><a name="SEC26" href="#TOC1">CALLOUTS</a><br>
  653. <P>
  654. <pre>
  655. (?C) callout (assumed number 0)
  656. (?Cn) callout with numerical data n
  657. (?C"text") callout with string data
  658. </pre>
  659. The allowed string delimiters are ` ' " ^ % # $ (which are the same for the
  660. start and the end), and the starting delimiter { matched with the ending
  661. delimiter }. To encode the ending delimiter within the string, double it.
  662. </P>
  663. <br><a name="SEC27" href="#TOC1">SEE ALSO</a><br>
  664. <P>
  665. <b>pcre2pattern</b>(3), <b>pcre2api</b>(3), <b>pcre2callout</b>(3),
  666. <b>pcre2matching</b>(3), <b>pcre2</b>(3).
  667. </P>
  668. <br><a name="SEC28" href="#TOC1">AUTHOR</a><br>
  669. <P>
  670. Philip Hazel
  671. <br>
  672. University Computing Service
  673. <br>
  674. Cambridge, England.
  675. <br>
  676. </P>
  677. <br><a name="SEC29" href="#TOC1">REVISION</a><br>
  678. <P>
  679. Last updated: 28 December 2019
  680. <br>
  681. Copyright &copy; 1997-2019 University of Cambridge.
  682. <br>
  683. <p>
  684. Return to the <a href="index.html">PCRE2 index page</a>.
  685. </p>