pcre2syntax.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. Cypro_Minoan,
  226. Cyrillic,
  227. Deseret,
  228. Devanagari,
  229. Dives_Akuru,
  230. Dogra,
  231. Duployan,
  232. Egyptian_Hieroglyphs,
  233. Elbasan,
  234. Elymaic,
  235. Ethiopic,
  236. Georgian,
  237. Glagolitic,
  238. Gothic,
  239. Grantha,
  240. Greek,
  241. Gujarati,
  242. Gunjala_Gondi,
  243. Gurmukhi,
  244. Han,
  245. Hangul,
  246. Hanifi_Rohingya,
  247. Hanunoo,
  248. Hatran,
  249. Hebrew,
  250. Hiragana,
  251. Imperial_Aramaic,
  252. Inherited,
  253. Inscriptional_Pahlavi,
  254. Inscriptional_Parthian,
  255. Javanese,
  256. Kaithi,
  257. Kannada,
  258. Katakana,
  259. Kayah_Li,
  260. Kharoshthi,
  261. Khitan_Small_Script,
  262. Khmer,
  263. Khojki,
  264. Khudawadi,
  265. Lao,
  266. Latin,
  267. Lepcha,
  268. Limbu,
  269. Linear_A,
  270. Linear_B,
  271. Lisu,
  272. Lycian,
  273. Lydian,
  274. Mahajani,
  275. Makasar,
  276. Malayalam,
  277. Mandaic,
  278. Manichaean,
  279. Marchen,
  280. Masaram_Gondi,
  281. Medefaidrin,
  282. Meetei_Mayek,
  283. Mende_Kikakui,
  284. Meroitic_Cursive,
  285. Meroitic_Hieroglyphs,
  286. Miao,
  287. Modi,
  288. Mongolian,
  289. Mro,
  290. Multani,
  291. Myanmar,
  292. Nabataean,
  293. Nandinagari,
  294. New_Tai_Lue,
  295. Newa,
  296. Nko,
  297. Nushu,
  298. Nyakeng_Puachue_Hmong,
  299. Ogham,
  300. Ol_Chiki,
  301. Old_Hungarian,
  302. Old_Italic,
  303. Old_North_Arabian,
  304. Old_Permic,
  305. Old_Persian,
  306. Old_Sogdian,
  307. Old_South_Arabian,
  308. Old_Turkic,
  309. Old_Uyghur,
  310. Oriya,
  311. Osage,
  312. Osmanya,
  313. Pahawh_Hmong,
  314. Palmyrene,
  315. Pau_Cin_Hau,
  316. Phags_Pa,
  317. Phoenician,
  318. Psalter_Pahlavi,
  319. Rejang,
  320. Runic,
  321. Samaritan,
  322. Saurashtra,
  323. Sharada,
  324. Shavian,
  325. Siddham,
  326. SignWriting,
  327. Sinhala,
  328. Sogdian,
  329. Sora_Sompeng,
  330. Soyombo,
  331. Sundanese,
  332. Syloti_Nagri,
  333. Syriac,
  334. Tagalog,
  335. Tagbanwa,
  336. Tai_Le,
  337. Tai_Tham,
  338. Tai_Viet,
  339. Takri,
  340. Tamil,
  341. Tangsa,
  342. Tangut,
  343. Telugu,
  344. Thaana,
  345. Thai,
  346. Tibetan,
  347. Tifinagh,
  348. Tirhuta,
  349. Toto,
  350. Ugaritic,
  351. Vai,
  352. Vithkuqi,
  353. Wancho,
  354. Warang_Citi,
  355. Yezidi,
  356. Yi,
  357. Zanabazar_Square.
  358. </P>
  359. <br><a name="SEC8" href="#TOC1">CHARACTER CLASSES</a><br>
  360. <P>
  361. <pre>
  362. [...] positive character class
  363. [^...] negative character class
  364. [x-y] range (can be used for hex characters)
  365. [[:xxx:]] positive POSIX named set
  366. [[:^xxx:]] negative POSIX named set
  367. alnum alphanumeric
  368. alpha alphabetic
  369. ascii 0-127
  370. blank space or tab
  371. cntrl control character
  372. digit decimal digit
  373. graph printing, excluding space
  374. lower lower case letter
  375. print printing, including space
  376. punct printing, excluding alphanumeric
  377. space white space
  378. upper upper case letter
  379. word same as \w
  380. xdigit hexadecimal digit
  381. </pre>
  382. In PCRE2, POSIX character set names recognize only ASCII characters by default,
  383. but some of them use Unicode properties if PCRE2_UCP is set. You can use
  384. \Q...\E inside a character class.
  385. </P>
  386. <br><a name="SEC9" href="#TOC1">QUANTIFIERS</a><br>
  387. <P>
  388. <pre>
  389. ? 0 or 1, greedy
  390. ?+ 0 or 1, possessive
  391. ?? 0 or 1, lazy
  392. * 0 or more, greedy
  393. *+ 0 or more, possessive
  394. *? 0 or more, lazy
  395. + 1 or more, greedy
  396. ++ 1 or more, possessive
  397. +? 1 or more, lazy
  398. {n} exactly n
  399. {n,m} at least n, no more than m, greedy
  400. {n,m}+ at least n, no more than m, possessive
  401. {n,m}? at least n, no more than m, lazy
  402. {n,} n or more, greedy
  403. {n,}+ n or more, possessive
  404. {n,}? n or more, lazy
  405. </PRE>
  406. </P>
  407. <br><a name="SEC10" href="#TOC1">ANCHORS AND SIMPLE ASSERTIONS</a><br>
  408. <P>
  409. <pre>
  410. \b word boundary
  411. \B not a word boundary
  412. ^ start of subject
  413. also after an internal newline in multiline mode
  414. (after any newline if PCRE2_ALT_CIRCUMFLEX is set)
  415. \A start of subject
  416. $ end of subject
  417. also before newline at end of subject
  418. also before internal newline in multiline mode
  419. \Z end of subject
  420. also before newline at end of subject
  421. \z end of subject
  422. \G first matching position in subject
  423. </PRE>
  424. </P>
  425. <br><a name="SEC11" href="#TOC1">REPORTED MATCH POINT SETTING</a><br>
  426. <P>
  427. <pre>
  428. \K set reported start of match
  429. </pre>
  430. From release 10.38 \K is not permitted by default in lookaround assertions,
  431. for compatibility with Perl. However, if the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK
  432. option is set, the previous behaviour is re-enabled. When this option is set,
  433. \K is honoured in positive assertions, but ignored in negative ones.
  434. </P>
  435. <br><a name="SEC12" href="#TOC1">ALTERNATION</a><br>
  436. <P>
  437. <pre>
  438. expr|expr|expr...
  439. </PRE>
  440. </P>
  441. <br><a name="SEC13" href="#TOC1">CAPTURING</a><br>
  442. <P>
  443. <pre>
  444. (...) capture group
  445. (?&#60;name&#62;...) named capture group (Perl)
  446. (?'name'...) named capture group (Perl)
  447. (?P&#60;name&#62;...) named capture group (Python)
  448. (?:...) non-capture group
  449. (?|...) non-capture group; reset group numbers for
  450. capture groups in each alternative
  451. </pre>
  452. In non-UTF modes, names may contain underscores and ASCII letters and digits;
  453. in UTF modes, any Unicode letters and Unicode decimal digits are permitted. In
  454. both cases, a name must not start with a digit.
  455. </P>
  456. <br><a name="SEC14" href="#TOC1">ATOMIC GROUPS</a><br>
  457. <P>
  458. <pre>
  459. (?&#62;...) atomic non-capture group
  460. (*atomic:...) atomic non-capture group
  461. </PRE>
  462. </P>
  463. <br><a name="SEC15" href="#TOC1">COMMENT</a><br>
  464. <P>
  465. <pre>
  466. (?#....) comment (not nestable)
  467. </PRE>
  468. </P>
  469. <br><a name="SEC16" href="#TOC1">OPTION SETTING</a><br>
  470. <P>
  471. Changes of these options within a group are automatically cancelled at the end
  472. of the group.
  473. <pre>
  474. (?i) caseless
  475. (?J) allow duplicate named groups
  476. (?m) multiline
  477. (?n) no auto capture
  478. (?s) single line (dotall)
  479. (?U) default ungreedy (lazy)
  480. (?x) extended: ignore white space except in classes
  481. (?xx) as (?x) but also ignore space and tab in classes
  482. (?-...) unset option(s)
  483. (?^) unset imnsx options
  484. </pre>
  485. Unsetting x or xx unsets both. Several options may be set at once, and a
  486. mixture of setting and unsetting such as (?i-x) is allowed, but there may be
  487. only one hyphen. Setting (but no unsetting) is allowed after (?^ for example
  488. (?^in). An option setting may appear at the start of a non-capture group, for
  489. example (?i:...).
  490. </P>
  491. <P>
  492. The following are recognized only at the very start of a pattern or after one
  493. of the newline or \R options with similar syntax. More than one of them may
  494. appear. For the first three, d is a decimal number.
  495. <pre>
  496. (*LIMIT_DEPTH=d) set the backtracking limit to d
  497. (*LIMIT_HEAP=d) set the heap size limit to d * 1024 bytes
  498. (*LIMIT_MATCH=d) set the match limit to d
  499. (*NOTEMPTY) set PCRE2_NOTEMPTY when matching
  500. (*NOTEMPTY_ATSTART) set PCRE2_NOTEMPTY_ATSTART when matching
  501. (*NO_AUTO_POSSESS) no auto-possessification (PCRE2_NO_AUTO_POSSESS)
  502. (*NO_DOTSTAR_ANCHOR) no .* anchoring (PCRE2_NO_DOTSTAR_ANCHOR)
  503. (*NO_JIT) disable JIT optimization
  504. (*NO_START_OPT) no start-match optimization (PCRE2_NO_START_OPTIMIZE)
  505. (*UTF) set appropriate UTF mode for the library in use
  506. (*UCP) set PCRE2_UCP (use Unicode properties for \d etc)
  507. </pre>
  508. Note that LIMIT_DEPTH, LIMIT_HEAP, and LIMIT_MATCH can only reduce the value of
  509. the limits set by the caller of <b>pcre2_match()</b> or <b>pcre2_dfa_match()</b>,
  510. not increase them. LIMIT_RECURSION is an obsolete synonym for LIMIT_DEPTH. The
  511. application can lock out the use of (*UTF) and (*UCP) by setting the
  512. PCRE2_NEVER_UTF or PCRE2_NEVER_UCP options, respectively, at compile time.
  513. </P>
  514. <br><a name="SEC17" href="#TOC1">NEWLINE CONVENTION</a><br>
  515. <P>
  516. These are recognized only at the very start of the pattern or after option
  517. settings with a similar syntax.
  518. <pre>
  519. (*CR) carriage return only
  520. (*LF) linefeed only
  521. (*CRLF) carriage return followed by linefeed
  522. (*ANYCRLF) all three of the above
  523. (*ANY) any Unicode newline sequence
  524. (*NUL) the NUL character (binary zero)
  525. </PRE>
  526. </P>
  527. <br><a name="SEC18" href="#TOC1">WHAT \R MATCHES</a><br>
  528. <P>
  529. These are recognized only at the very start of the pattern or after option
  530. setting with a similar syntax.
  531. <pre>
  532. (*BSR_ANYCRLF) CR, LF, or CRLF
  533. (*BSR_UNICODE) any Unicode newline sequence
  534. </PRE>
  535. </P>
  536. <br><a name="SEC19" href="#TOC1">LOOKAHEAD AND LOOKBEHIND ASSERTIONS</a><br>
  537. <P>
  538. <pre>
  539. (?=...) )
  540. (*pla:...) ) positive lookahead
  541. (*positive_lookahead:...) )
  542. (?!...) )
  543. (*nla:...) ) negative lookahead
  544. (*negative_lookahead:...) )
  545. (?&#60;=...) )
  546. (*plb:...) ) positive lookbehind
  547. (*positive_lookbehind:...) )
  548. (?&#60;!...) )
  549. (*nlb:...) ) negative lookbehind
  550. (*negative_lookbehind:...) )
  551. </pre>
  552. Each top-level branch of a lookbehind must be of a fixed length.
  553. </P>
  554. <br><a name="SEC20" href="#TOC1">NON-ATOMIC LOOKAROUND ASSERTIONS</a><br>
  555. <P>
  556. These assertions are specific to PCRE2 and are not Perl-compatible.
  557. <pre>
  558. (?*...) )
  559. (*napla:...) ) synonyms
  560. (*non_atomic_positive_lookahead:...) )
  561. (?&#60;*...) )
  562. (*naplb:...) ) synonyms
  563. (*non_atomic_positive_lookbehind:...) )
  564. </PRE>
  565. </P>
  566. <br><a name="SEC21" href="#TOC1">SCRIPT RUNS</a><br>
  567. <P>
  568. <pre>
  569. (*script_run:...) ) script run, can be backtracked into
  570. (*sr:...) )
  571. (*atomic_script_run:...) ) atomic script run
  572. (*asr:...) )
  573. </PRE>
  574. </P>
  575. <br><a name="SEC22" href="#TOC1">BACKREFERENCES</a><br>
  576. <P>
  577. <pre>
  578. \n reference by number (can be ambiguous)
  579. \gn reference by number
  580. \g{n} reference by number
  581. \g+n relative reference by number (PCRE2 extension)
  582. \g-n relative reference by number
  583. \g{+n} relative reference by number (PCRE2 extension)
  584. \g{-n} relative reference by number
  585. \k&#60;name&#62; reference by name (Perl)
  586. \k'name' reference by name (Perl)
  587. \g{name} reference by name (Perl)
  588. \k{name} reference by name (.NET)
  589. (?P=name) reference by name (Python)
  590. </PRE>
  591. </P>
  592. <br><a name="SEC23" href="#TOC1">SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)</a><br>
  593. <P>
  594. <pre>
  595. (?R) recurse whole pattern
  596. (?n) call subroutine by absolute number
  597. (?+n) call subroutine by relative number
  598. (?-n) call subroutine by relative number
  599. (?&name) call subroutine by name (Perl)
  600. (?P&#62;name) call subroutine by name (Python)
  601. \g&#60;name&#62; call subroutine by name (Oniguruma)
  602. \g'name' call subroutine by name (Oniguruma)
  603. \g&#60;n&#62; call subroutine by absolute number (Oniguruma)
  604. \g'n' call subroutine by absolute number (Oniguruma)
  605. \g&#60;+n&#62; call subroutine by relative number (PCRE2 extension)
  606. \g'+n' call subroutine by relative number (PCRE2 extension)
  607. \g&#60;-n&#62; call subroutine by relative number (PCRE2 extension)
  608. \g'-n' call subroutine by relative number (PCRE2 extension)
  609. </PRE>
  610. </P>
  611. <br><a name="SEC24" href="#TOC1">CONDITIONAL PATTERNS</a><br>
  612. <P>
  613. <pre>
  614. (?(condition)yes-pattern)
  615. (?(condition)yes-pattern|no-pattern)
  616. (?(n) absolute reference condition
  617. (?(+n) relative reference condition
  618. (?(-n) relative reference condition
  619. (?(&#60;name&#62;) named reference condition (Perl)
  620. (?('name') named reference condition (Perl)
  621. (?(name) named reference condition (PCRE2, deprecated)
  622. (?(R) overall recursion condition
  623. (?(Rn) specific numbered group recursion condition
  624. (?(R&name) specific named group recursion condition
  625. (?(DEFINE) define groups for reference
  626. (?(VERSION[&#62;]=n.m) test PCRE2 version
  627. (?(assert) assertion condition
  628. </pre>
  629. Note the ambiguity of (?(R) and (?(Rn) which might be named reference
  630. conditions or recursion tests. Such a condition is interpreted as a reference
  631. condition if the relevant named group exists.
  632. </P>
  633. <br><a name="SEC25" href="#TOC1">BACKTRACKING CONTROL</a><br>
  634. <P>
  635. All backtracking control verbs may be in the form (*VERB:NAME). For (*MARK) the
  636. name is mandatory, for the others it is optional. (*SKIP) changes its behaviour
  637. if :NAME is present. The others just set a name for passing back to the caller,
  638. but this is not a name that (*SKIP) can see. The following act immediately they
  639. are reached:
  640. <pre>
  641. (*ACCEPT) force successful match
  642. (*FAIL) force backtrack; synonym (*F)
  643. (*MARK:NAME) set name to be passed back; synonym (*:NAME)
  644. </pre>
  645. The following act only when a subsequent match failure causes a backtrack to
  646. reach them. They all force a match failure, but they differ in what happens
  647. afterwards. Those that advance the start-of-match point do so only if the
  648. pattern is not anchored.
  649. <pre>
  650. (*COMMIT) overall failure, no advance of starting point
  651. (*PRUNE) advance to next starting character
  652. (*SKIP) advance to current matching position
  653. (*SKIP:NAME) advance to position corresponding to an earlier
  654. (*MARK:NAME); if not found, the (*SKIP) is ignored
  655. (*THEN) local failure, backtrack to next alternation
  656. </pre>
  657. The effect of one of these verbs in a group called as a subroutine is confined
  658. to the subroutine call.
  659. </P>
  660. <br><a name="SEC26" href="#TOC1">CALLOUTS</a><br>
  661. <P>
  662. <pre>
  663. (?C) callout (assumed number 0)
  664. (?Cn) callout with numerical data n
  665. (?C"text") callout with string data
  666. </pre>
  667. The allowed string delimiters are ` ' " ^ % # $ (which are the same for the
  668. start and the end), and the starting delimiter { matched with the ending
  669. delimiter }. To encode the ending delimiter within the string, double it.
  670. </P>
  671. <br><a name="SEC27" href="#TOC1">SEE ALSO</a><br>
  672. <P>
  673. <b>pcre2pattern</b>(3), <b>pcre2api</b>(3), <b>pcre2callout</b>(3),
  674. <b>pcre2matching</b>(3), <b>pcre2</b>(3).
  675. </P>
  676. <br><a name="SEC28" href="#TOC1">AUTHOR</a><br>
  677. <P>
  678. Philip Hazel
  679. <br>
  680. Retired from University Computing Service
  681. <br>
  682. Cambridge, England.
  683. <br>
  684. </P>
  685. <br><a name="SEC29" href="#TOC1">REVISION</a><br>
  686. <P>
  687. Last updated: 30 August 2021
  688. <br>
  689. Copyright &copy; 1997-2021 University of Cambridge.
  690. <br>
  691. <p>
  692. Return to the <a href="index.html">PCRE2 index page</a>.
  693. </p>