pcre2api.3 174 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021
  1. .TH PCRE2API 3 "30 August 2021" "PCRE2 10.38"
  2. .SH NAME
  3. PCRE2 - Perl-compatible regular expressions (revised API)
  4. .sp
  5. .B #include <pcre2.h>
  6. .sp
  7. PCRE2 is a new API for PCRE, starting at release 10.0. This document contains a
  8. description of all its native functions. See the
  9. .\" HREF
  10. \fBpcre2\fP
  11. .\"
  12. document for an overview of all the PCRE2 documentation.
  13. .
  14. .
  15. .SH "PCRE2 NATIVE API BASIC FUNCTIONS"
  16. .rs
  17. .sp
  18. .nf
  19. .B pcre2_code *pcre2_compile(PCRE2_SPTR \fIpattern\fP, PCRE2_SIZE \fIlength\fP,
  20. .B " uint32_t \fIoptions\fP, int *\fIerrorcode\fP, PCRE2_SIZE *\fIerroroffset,\fP"
  21. .B " pcre2_compile_context *\fIccontext\fP);"
  22. .sp
  23. .B void pcre2_code_free(pcre2_code *\fIcode\fP);
  24. .sp
  25. .B pcre2_match_data *pcre2_match_data_create(uint32_t \fIovecsize\fP,
  26. .B " pcre2_general_context *\fIgcontext\fP);"
  27. .sp
  28. .B pcre2_match_data *pcre2_match_data_create_from_pattern(
  29. .B " const pcre2_code *\fIcode\fP, pcre2_general_context *\fIgcontext\fP);"
  30. .sp
  31. .B int pcre2_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  32. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  33. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  34. .B " pcre2_match_context *\fImcontext\fP);"
  35. .sp
  36. .B int pcre2_dfa_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  37. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  38. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  39. .B " pcre2_match_context *\fImcontext\fP,"
  40. .B " int *\fIworkspace\fP, PCRE2_SIZE \fIwscount\fP);"
  41. .sp
  42. .B void pcre2_match_data_free(pcre2_match_data *\fImatch_data\fP);
  43. .fi
  44. .
  45. .
  46. .SH "PCRE2 NATIVE API AUXILIARY MATCH FUNCTIONS"
  47. .rs
  48. .sp
  49. .nf
  50. .B PCRE2_SPTR pcre2_get_mark(pcre2_match_data *\fImatch_data\fP);
  51. .sp
  52. .B uint32_t pcre2_get_ovector_count(pcre2_match_data *\fImatch_data\fP);
  53. .sp
  54. .B PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *\fImatch_data\fP);
  55. .sp
  56. .B PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *\fImatch_data\fP);
  57. .fi
  58. .
  59. .
  60. .SH "PCRE2 NATIVE API GENERAL CONTEXT FUNCTIONS"
  61. .rs
  62. .sp
  63. .nf
  64. .B pcre2_general_context *pcre2_general_context_create(
  65. .B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
  66. .B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
  67. .sp
  68. .B pcre2_general_context *pcre2_general_context_copy(
  69. .B " pcre2_general_context *\fIgcontext\fP);"
  70. .sp
  71. .B void pcre2_general_context_free(pcre2_general_context *\fIgcontext\fP);
  72. .fi
  73. .
  74. .
  75. .SH "PCRE2 NATIVE API COMPILE CONTEXT FUNCTIONS"
  76. .rs
  77. .sp
  78. .nf
  79. .B pcre2_compile_context *pcre2_compile_context_create(
  80. .B " pcre2_general_context *\fIgcontext\fP);"
  81. .sp
  82. .B pcre2_compile_context *pcre2_compile_context_copy(
  83. .B " pcre2_compile_context *\fIccontext\fP);"
  84. .sp
  85. .B void pcre2_compile_context_free(pcre2_compile_context *\fIccontext\fP);
  86. .sp
  87. .B int pcre2_set_bsr(pcre2_compile_context *\fIccontext\fP,
  88. .B " uint32_t \fIvalue\fP);"
  89. .sp
  90. .B int pcre2_set_character_tables(pcre2_compile_context *\fIccontext\fP,
  91. .B " const uint8_t *\fItables\fP);"
  92. .sp
  93. .B int pcre2_set_compile_extra_options(pcre2_compile_context *\fIccontext\fP,
  94. .B " uint32_t \fIextra_options\fP);"
  95. .sp
  96. .B int pcre2_set_max_pattern_length(pcre2_compile_context *\fIccontext\fP,
  97. .B " PCRE2_SIZE \fIvalue\fP);"
  98. .sp
  99. .B int pcre2_set_newline(pcre2_compile_context *\fIccontext\fP,
  100. .B " uint32_t \fIvalue\fP);"
  101. .sp
  102. .B int pcre2_set_parens_nest_limit(pcre2_compile_context *\fIccontext\fP,
  103. .B " uint32_t \fIvalue\fP);"
  104. .sp
  105. .B int pcre2_set_compile_recursion_guard(pcre2_compile_context *\fIccontext\fP,
  106. .B " int (*\fIguard_function\fP)(uint32_t, void *), void *\fIuser_data\fP);"
  107. .fi
  108. .
  109. .
  110. .SH "PCRE2 NATIVE API MATCH CONTEXT FUNCTIONS"
  111. .rs
  112. .sp
  113. .nf
  114. .B pcre2_match_context *pcre2_match_context_create(
  115. .B " pcre2_general_context *\fIgcontext\fP);"
  116. .sp
  117. .B pcre2_match_context *pcre2_match_context_copy(
  118. .B " pcre2_match_context *\fImcontext\fP);"
  119. .sp
  120. .B void pcre2_match_context_free(pcre2_match_context *\fImcontext\fP);
  121. .sp
  122. .B int pcre2_set_callout(pcre2_match_context *\fImcontext\fP,
  123. .B " int (*\fIcallout_function\fP)(pcre2_callout_block *, void *),"
  124. .B " void *\fIcallout_data\fP);"
  125. .sp
  126. .B int pcre2_set_substitute_callout(pcre2_match_context *\fImcontext\fP,
  127. .B " int (*\fIcallout_function\fP)(pcre2_substitute_callout_block *, void *),"
  128. .B " void *\fIcallout_data\fP);"
  129. .sp
  130. .B int pcre2_set_offset_limit(pcre2_match_context *\fImcontext\fP,
  131. .B " PCRE2_SIZE \fIvalue\fP);"
  132. .sp
  133. .B int pcre2_set_heap_limit(pcre2_match_context *\fImcontext\fP,
  134. .B " uint32_t \fIvalue\fP);"
  135. .sp
  136. .B int pcre2_set_match_limit(pcre2_match_context *\fImcontext\fP,
  137. .B " uint32_t \fIvalue\fP);"
  138. .sp
  139. .B int pcre2_set_depth_limit(pcre2_match_context *\fImcontext\fP,
  140. .B " uint32_t \fIvalue\fP);"
  141. .fi
  142. .
  143. .
  144. .SH "PCRE2 NATIVE API STRING EXTRACTION FUNCTIONS"
  145. .rs
  146. .sp
  147. .nf
  148. .B int pcre2_substring_copy_byname(pcre2_match_data *\fImatch_data\fP,
  149. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR *\fIbuffer\fP, PCRE2_SIZE *\fIbufflen\fP);"
  150. .sp
  151. .B int pcre2_substring_copy_bynumber(pcre2_match_data *\fImatch_data\fP,
  152. .B " uint32_t \fInumber\fP, PCRE2_UCHAR *\fIbuffer\fP,"
  153. .B " PCRE2_SIZE *\fIbufflen\fP);"
  154. .sp
  155. .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP);
  156. .sp
  157. .B int pcre2_substring_get_byname(pcre2_match_data *\fImatch_data\fP,
  158. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR **\fIbufferptr\fP, PCRE2_SIZE *\fIbufflen\fP);"
  159. .sp
  160. .B int pcre2_substring_get_bynumber(pcre2_match_data *\fImatch_data\fP,
  161. .B " uint32_t \fInumber\fP, PCRE2_UCHAR **\fIbufferptr\fP,"
  162. .B " PCRE2_SIZE *\fIbufflen\fP);"
  163. .sp
  164. .B int pcre2_substring_length_byname(pcre2_match_data *\fImatch_data\fP,
  165. .B " PCRE2_SPTR \fIname\fP, PCRE2_SIZE *\fIlength\fP);"
  166. .sp
  167. .B int pcre2_substring_length_bynumber(pcre2_match_data *\fImatch_data\fP,
  168. .B " uint32_t \fInumber\fP, PCRE2_SIZE *\fIlength\fP);"
  169. .sp
  170. .B int pcre2_substring_nametable_scan(const pcre2_code *\fIcode\fP,
  171. .B " PCRE2_SPTR \fIname\fP, PCRE2_SPTR *\fIfirst\fP, PCRE2_SPTR *\fIlast\fP);"
  172. .sp
  173. .B int pcre2_substring_number_from_name(const pcre2_code *\fIcode\fP,
  174. .B " PCRE2_SPTR \fIname\fP);"
  175. .sp
  176. .B void pcre2_substring_list_free(PCRE2_SPTR *\fIlist\fP);
  177. .sp
  178. .B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP,
  179. .B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP);
  180. .fi
  181. .
  182. .
  183. .SH "PCRE2 NATIVE API STRING SUBSTITUTION FUNCTION"
  184. .rs
  185. .sp
  186. .nf
  187. .B int pcre2_substitute(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  188. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  189. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  190. .B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacementz\fP,"
  191. .B " PCRE2_SIZE \fIrlength\fP, PCRE2_UCHAR *\fIoutputbuffer\fP,"
  192. .B " PCRE2_SIZE *\fIoutlengthptr\fP);"
  193. .fi
  194. .
  195. .
  196. .SH "PCRE2 NATIVE API JIT FUNCTIONS"
  197. .rs
  198. .sp
  199. .nf
  200. .B int pcre2_jit_compile(pcre2_code *\fIcode\fP, uint32_t \fIoptions\fP);
  201. .sp
  202. .B int pcre2_jit_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  203. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  204. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  205. .B " pcre2_match_context *\fImcontext\fP);"
  206. .sp
  207. .B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP);
  208. .sp
  209. .B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
  210. .B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
  211. .sp
  212. .B void pcre2_jit_stack_assign(pcre2_match_context *\fImcontext\fP,
  213. .B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);"
  214. .sp
  215. .B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP);
  216. .fi
  217. .
  218. .
  219. .SH "PCRE2 NATIVE API SERIALIZATION FUNCTIONS"
  220. .rs
  221. .sp
  222. .nf
  223. .B int32_t pcre2_serialize_decode(pcre2_code **\fIcodes\fP,
  224. .B " int32_t \fInumber_of_codes\fP, const uint8_t *\fIbytes\fP,"
  225. .B " pcre2_general_context *\fIgcontext\fP);"
  226. .sp
  227. .B int32_t pcre2_serialize_encode(const pcre2_code **\fIcodes\fP,
  228. .B " int32_t \fInumber_of_codes\fP, uint8_t **\fIserialized_bytes\fP,"
  229. .B " PCRE2_SIZE *\fIserialized_size\fP, pcre2_general_context *\fIgcontext\fP);"
  230. .sp
  231. .B void pcre2_serialize_free(uint8_t *\fIbytes\fP);
  232. .sp
  233. .B int32_t pcre2_serialize_get_number_of_codes(const uint8_t *\fIbytes\fP);
  234. .fi
  235. .
  236. .
  237. .SH "PCRE2 NATIVE API AUXILIARY FUNCTIONS"
  238. .rs
  239. .sp
  240. .nf
  241. .B pcre2_code *pcre2_code_copy(const pcre2_code *\fIcode\fP);
  242. .sp
  243. .B pcre2_code *pcre2_code_copy_with_tables(const pcre2_code *\fIcode\fP);
  244. .sp
  245. .B int pcre2_get_error_message(int \fIerrorcode\fP, PCRE2_UCHAR *\fIbuffer\fP,
  246. .B " PCRE2_SIZE \fIbufflen\fP);"
  247. .sp
  248. .B const uint8_t *pcre2_maketables(pcre2_general_context *\fIgcontext\fP);
  249. .sp
  250. .B void pcre2_maketables_free(pcre2_general_context *\fIgcontext\fP,
  251. .B " const uint8_t *\fItables\fP);"
  252. .sp
  253. .B int pcre2_pattern_info(const pcre2_code *\fIcode\fP, uint32_t \fIwhat\fP,
  254. .B " void *\fIwhere\fP);"
  255. .sp
  256. .B int pcre2_callout_enumerate(const pcre2_code *\fIcode\fP,
  257. .B " int (*\fIcallback\fP)(pcre2_callout_enumerate_block *, void *),"
  258. .B " void *\fIuser_data\fP);"
  259. .sp
  260. .B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP);
  261. .fi
  262. .
  263. .
  264. .SH "PCRE2 NATIVE API OBSOLETE FUNCTIONS"
  265. .rs
  266. .sp
  267. .nf
  268. .B int pcre2_set_recursion_limit(pcre2_match_context *\fImcontext\fP,
  269. .B " uint32_t \fIvalue\fP);"
  270. .sp
  271. .B int pcre2_set_recursion_memory_management(
  272. .B " pcre2_match_context *\fImcontext\fP,"
  273. .B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
  274. .B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
  275. .fi
  276. .sp
  277. These functions became obsolete at release 10.30 and are retained only for
  278. backward compatibility. They should not be used in new code. The first is
  279. replaced by \fBpcre2_set_depth_limit()\fP; the second is no longer needed and
  280. has no effect (it always returns zero).
  281. .
  282. .
  283. .SH "PCRE2 EXPERIMENTAL PATTERN CONVERSION FUNCTIONS"
  284. .rs
  285. .sp
  286. .nf
  287. .B pcre2_convert_context *pcre2_convert_context_create(
  288. .B " pcre2_general_context *\fIgcontext\fP);"
  289. .sp
  290. .B pcre2_convert_context *pcre2_convert_context_copy(
  291. .B " pcre2_convert_context *\fIcvcontext\fP);"
  292. .sp
  293. .B void pcre2_convert_context_free(pcre2_convert_context *\fIcvcontext\fP);
  294. .sp
  295. .B int pcre2_set_glob_escape(pcre2_convert_context *\fIcvcontext\fP,
  296. .B " uint32_t \fIescape_char\fP);"
  297. .sp
  298. .B int pcre2_set_glob_separator(pcre2_convert_context *\fIcvcontext\fP,
  299. .B " uint32_t \fIseparator_char\fP);"
  300. .sp
  301. .B int pcre2_pattern_convert(PCRE2_SPTR \fIpattern\fP, PCRE2_SIZE \fIlength\fP,
  302. .B " uint32_t \fIoptions\fP, PCRE2_UCHAR **\fIbuffer\fP,"
  303. .B " PCRE2_SIZE *\fIblength\fP, pcre2_convert_context *\fIcvcontext\fP);"
  304. .sp
  305. .B void pcre2_converted_pattern_free(PCRE2_UCHAR *\fIconverted_pattern\fP);
  306. .fi
  307. .sp
  308. These functions provide a way of converting non-PCRE2 patterns into
  309. patterns that can be processed by \fBpcre2_compile()\fP. This facility is
  310. experimental and may be changed in future releases. At present, "globs" and
  311. POSIX basic and extended patterns can be converted. Details are given in the
  312. .\" HREF
  313. \fBpcre2convert\fP
  314. .\"
  315. documentation.
  316. .
  317. .
  318. .SH "PCRE2 8-BIT, 16-BIT, AND 32-BIT LIBRARIES"
  319. .rs
  320. .sp
  321. There are three PCRE2 libraries, supporting 8-bit, 16-bit, and 32-bit code
  322. units, respectively. However, there is just one header file, \fBpcre2.h\fP.
  323. This contains the function prototypes and other definitions for all three
  324. libraries. One, two, or all three can be installed simultaneously. On Unix-like
  325. systems the libraries are called \fBlibpcre2-8\fP, \fBlibpcre2-16\fP, and
  326. \fBlibpcre2-32\fP, and they can also co-exist with the original PCRE libraries.
  327. .P
  328. Character strings are passed to and from a PCRE2 library as a sequence of
  329. unsigned integers in code units of the appropriate width. Every PCRE2 function
  330. comes in three different forms, one for each library, for example:
  331. .sp
  332. \fBpcre2_compile_8()\fP
  333. \fBpcre2_compile_16()\fP
  334. \fBpcre2_compile_32()\fP
  335. .sp
  336. There are also three different sets of data types:
  337. .sp
  338. \fBPCRE2_UCHAR8, PCRE2_UCHAR16, PCRE2_UCHAR32\fP
  339. \fBPCRE2_SPTR8, PCRE2_SPTR16, PCRE2_SPTR32\fP
  340. .sp
  341. The UCHAR types define unsigned code units of the appropriate widths. For
  342. example, PCRE2_UCHAR16 is usually defined as `uint16_t'. The SPTR types are
  343. constant pointers to the equivalent UCHAR types, that is, they are pointers to
  344. vectors of unsigned code units.
  345. .P
  346. Many applications use only one code unit width. For their convenience, macros
  347. are defined whose names are the generic forms such as \fBpcre2_compile()\fP and
  348. PCRE2_SPTR. These macros use the value of the macro PCRE2_CODE_UNIT_WIDTH to
  349. generate the appropriate width-specific function and macro names.
  350. PCRE2_CODE_UNIT_WIDTH is not defined by default. An application must define it
  351. to be 8, 16, or 32 before including \fBpcre2.h\fP in order to make use of the
  352. generic names.
  353. .P
  354. Applications that use more than one code unit width can be linked with more
  355. than one PCRE2 library, but must define PCRE2_CODE_UNIT_WIDTH to be 0 before
  356. including \fBpcre2.h\fP, and then use the real function names. Any code that is
  357. to be included in an environment where the value of PCRE2_CODE_UNIT_WIDTH is
  358. unknown should also use the real function names. (Unfortunately, it is not
  359. possible in C code to save and restore the value of a macro.)
  360. .P
  361. If PCRE2_CODE_UNIT_WIDTH is not defined before including \fBpcre2.h\fP, a
  362. compiler error occurs.
  363. .P
  364. When using multiple libraries in an application, you must take care when
  365. processing any particular pattern to use only functions from a single library.
  366. For example, if you want to run a match using a pattern that was compiled with
  367. \fBpcre2_compile_16()\fP, you must do so with \fBpcre2_match_16()\fP, not
  368. \fBpcre2_match_8()\fP or \fBpcre2_match_32()\fP.
  369. .P
  370. In the function summaries above, and in the rest of this document and other
  371. PCRE2 documents, functions and data types are described using their generic
  372. names, without the _8, _16, or _32 suffix.
  373. .
  374. .
  375. .SH "PCRE2 API OVERVIEW"
  376. .rs
  377. .sp
  378. PCRE2 has its own native API, which is described in this document. There are
  379. also some wrapper functions for the 8-bit library that correspond to the
  380. POSIX regular expression API, but they do not give access to all the
  381. functionality of PCRE2. They are described in the
  382. .\" HREF
  383. \fBpcre2posix\fP
  384. .\"
  385. documentation. Both these APIs define a set of C function calls.
  386. .P
  387. The native API C data types, function prototypes, option values, and error
  388. codes are defined in the header file \fBpcre2.h\fP, which also contains
  389. definitions of PCRE2_MAJOR and PCRE2_MINOR, the major and minor release numbers
  390. for the library. Applications can use these to include support for different
  391. releases of PCRE2.
  392. .P
  393. In a Windows environment, if you want to statically link an application program
  394. against a non-dll PCRE2 library, you must define PCRE2_STATIC before including
  395. \fBpcre2.h\fP.
  396. .P
  397. The functions \fBpcre2_compile()\fP and \fBpcre2_match()\fP are used for
  398. compiling and matching regular expressions in a Perl-compatible manner. A
  399. sample program that demonstrates the simplest way of using them is provided in
  400. the file called \fIpcre2demo.c\fP in the PCRE2 source distribution. A listing
  401. of this program is given in the
  402. .\" HREF
  403. \fBpcre2demo\fP
  404. .\"
  405. documentation, and the
  406. .\" HREF
  407. \fBpcre2sample\fP
  408. .\"
  409. documentation describes how to compile and run it.
  410. .P
  411. The compiling and matching functions recognize various options that are passed
  412. as bits in an options argument. There are also some more complicated parameters
  413. such as custom memory management functions and resource limits that are passed
  414. in "contexts" (which are just memory blocks, described below). Simple
  415. applications do not need to make use of contexts.
  416. .P
  417. Just-in-time (JIT) compiler support is an optional feature of PCRE2 that can be
  418. built in appropriate hardware environments. It greatly speeds up the matching
  419. performance of many patterns. Programs can request that it be used if
  420. available by calling \fBpcre2_jit_compile()\fP after a pattern has been
  421. successfully compiled by \fBpcre2_compile()\fP. This does nothing if JIT
  422. support is not available.
  423. .P
  424. More complicated programs might need to make use of the specialist functions
  425. \fBpcre2_jit_stack_create()\fP, \fBpcre2_jit_stack_free()\fP, and
  426. \fBpcre2_jit_stack_assign()\fP in order to control the JIT code's memory usage.
  427. .P
  428. JIT matching is automatically used by \fBpcre2_match()\fP if it is available,
  429. unless the PCRE2_NO_JIT option is set. There is also a direct interface for JIT
  430. matching, which gives improved performance at the expense of less sanity
  431. checking. The JIT-specific functions are discussed in the
  432. .\" HREF
  433. \fBpcre2jit\fP
  434. .\"
  435. documentation.
  436. .P
  437. A second matching function, \fBpcre2_dfa_match()\fP, which is not
  438. Perl-compatible, is also provided. This uses a different algorithm for the
  439. matching. The alternative algorithm finds all possible matches (at a given
  440. point in the subject), and scans the subject just once (unless there are
  441. lookaround assertions). However, this algorithm does not return captured
  442. substrings. A description of the two matching algorithms and their advantages
  443. and disadvantages is given in the
  444. .\" HREF
  445. \fBpcre2matching\fP
  446. .\"
  447. documentation. There is no JIT support for \fBpcre2_dfa_match()\fP.
  448. .P
  449. In addition to the main compiling and matching functions, there are convenience
  450. functions for extracting captured substrings from a subject string that has
  451. been matched by \fBpcre2_match()\fP. They are:
  452. .sp
  453. \fBpcre2_substring_copy_byname()\fP
  454. \fBpcre2_substring_copy_bynumber()\fP
  455. \fBpcre2_substring_get_byname()\fP
  456. \fBpcre2_substring_get_bynumber()\fP
  457. \fBpcre2_substring_list_get()\fP
  458. \fBpcre2_substring_length_byname()\fP
  459. \fBpcre2_substring_length_bynumber()\fP
  460. \fBpcre2_substring_nametable_scan()\fP
  461. \fBpcre2_substring_number_from_name()\fP
  462. .sp
  463. \fBpcre2_substring_free()\fP and \fBpcre2_substring_list_free()\fP are also
  464. provided, to free memory used for extracted strings. If either of these
  465. functions is called with a NULL argument, the function returns immediately
  466. without doing anything.
  467. .P
  468. The function \fBpcre2_substitute()\fP can be called to match a pattern and
  469. return a copy of the subject string with substitutions for parts that were
  470. matched.
  471. .P
  472. Functions whose names begin with \fBpcre2_serialize_\fP are used for saving
  473. compiled patterns on disc or elsewhere, and reloading them later.
  474. .P
  475. Finally, there are functions for finding out information about a compiled
  476. pattern (\fBpcre2_pattern_info()\fP) and about the configuration with which
  477. PCRE2 was built (\fBpcre2_config()\fP).
  478. .P
  479. Functions with names ending with \fB_free()\fP are used for freeing memory
  480. blocks of various sorts. In all cases, if one of these functions is called with
  481. a NULL argument, it does nothing.
  482. .
  483. .
  484. .SH "STRING LENGTHS AND OFFSETS"
  485. .rs
  486. .sp
  487. The PCRE2 API uses string lengths and offsets into strings of code units in
  488. several places. These values are always of type PCRE2_SIZE, which is an
  489. unsigned integer type, currently always defined as \fIsize_t\fP. The largest
  490. value that can be stored in such a type (that is ~(PCRE2_SIZE)0) is reserved
  491. as a special indicator for zero-terminated strings and unset offsets.
  492. Therefore, the longest string that can be handled is one less than this
  493. maximum.
  494. .
  495. .
  496. .\" HTML <a name="newlines"></a>
  497. .SH NEWLINES
  498. .rs
  499. .sp
  500. PCRE2 supports five different conventions for indicating line breaks in
  501. strings: a single CR (carriage return) character, a single LF (linefeed)
  502. character, the two-character sequence CRLF, any of the three preceding, or any
  503. Unicode newline sequence. The Unicode newline sequences are the three just
  504. mentioned, plus the single characters VT (vertical tab, U+000B), FF (form feed,
  505. U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
  506. (paragraph separator, U+2029).
  507. .P
  508. Each of the first three conventions is used by at least one operating system as
  509. its standard newline sequence. When PCRE2 is built, a default can be specified.
  510. If it is not, the default is set to LF, which is the Unix standard. However,
  511. the newline convention can be changed by an application when calling
  512. \fBpcre2_compile()\fP, or it can be specified by special text at the start of
  513. the pattern itself; this overrides any other settings. See the
  514. .\" HREF
  515. \fBpcre2pattern\fP
  516. .\"
  517. page for details of the special character sequences.
  518. .P
  519. In the PCRE2 documentation the word "newline" is used to mean "the character or
  520. pair of characters that indicate a line break". The choice of newline
  521. convention affects the handling of the dot, circumflex, and dollar
  522. metacharacters, the handling of #-comments in /x mode, and, when CRLF is a
  523. recognized line ending sequence, the match position advancement for a
  524. non-anchored pattern. There is more detail about this in the
  525. .\" HTML <a href="#matchoptions">
  526. .\" </a>
  527. section on \fBpcre2_match()\fP options
  528. .\"
  529. below.
  530. .P
  531. The choice of newline convention does not affect the interpretation of
  532. the \en or \er escape sequences, nor does it affect what \eR matches; this has
  533. its own separate convention.
  534. .
  535. .
  536. .SH MULTITHREADING
  537. .rs
  538. .sp
  539. In a multithreaded application it is important to keep thread-specific data
  540. separate from data that can be shared between threads. The PCRE2 library code
  541. itself is thread-safe: it contains no static or global variables. The API is
  542. designed to be fairly simple for non-threaded applications while at the same
  543. time ensuring that multithreaded applications can use it.
  544. .P
  545. There are several different blocks of data that are used to pass information
  546. between the application and the PCRE2 libraries.
  547. .
  548. .
  549. .SS "The compiled pattern"
  550. .rs
  551. .sp
  552. A pointer to the compiled form of a pattern is returned to the user when
  553. \fBpcre2_compile()\fP is successful. The data in the compiled pattern is fixed,
  554. and does not change when the pattern is matched. Therefore, it is thread-safe,
  555. that is, the same compiled pattern can be used by more than one thread
  556. simultaneously. For example, an application can compile all its patterns at the
  557. start, before forking off multiple threads that use them. However, if the
  558. just-in-time (JIT) optimization feature is being used, it needs separate memory
  559. stack areas for each thread. See the
  560. .\" HREF
  561. \fBpcre2jit\fP
  562. .\"
  563. documentation for more details.
  564. .P
  565. In a more complicated situation, where patterns are compiled only when they are
  566. first needed, but are still shared between threads, pointers to compiled
  567. patterns must be protected from simultaneous writing by multiple threads. This
  568. is somewhat tricky to do correctly. If you know that writing to a pointer is
  569. atomic in your environment, you can use logic like this:
  570. .sp
  571. Get a read-only (shared) lock (mutex) for pointer
  572. if (pointer == NULL)
  573. {
  574. Get a write (unique) lock for pointer
  575. if (pointer == NULL) pointer = pcre2_compile(...
  576. }
  577. Release the lock
  578. Use pointer in pcre2_match()
  579. .sp
  580. Of course, testing for compilation errors should also be included in the code.
  581. .P
  582. The reason for checking the pointer a second time is as follows: Several
  583. threads may have acquired the shared lock and tested the pointer for being
  584. NULL, but only one of them will be given the write lock, with the rest kept
  585. waiting. The winning thread will compile the pattern and store the result.
  586. After this thread releases the write lock, another thread will get it, and if
  587. it does not retest pointer for being NULL, will recompile the pattern and
  588. overwrite the pointer, creating a memory leak and possibly causing other
  589. issues.
  590. .P
  591. In an environment where writing to a pointer may not be atomic, the above logic
  592. is not sufficient. The thread that is doing the compiling may be descheduled
  593. after writing only part of the pointer, which could cause other threads to use
  594. an invalid value. Instead of checking the pointer itself, a separate "pointer
  595. is valid" flag (that can be updated atomically) must be used:
  596. .sp
  597. Get a read-only (shared) lock (mutex) for pointer
  598. if (!pointer_is_valid)
  599. {
  600. Get a write (unique) lock for pointer
  601. if (!pointer_is_valid)
  602. {
  603. pointer = pcre2_compile(...
  604. pointer_is_valid = TRUE
  605. }
  606. }
  607. Release the lock
  608. Use pointer in pcre2_match()
  609. .sp
  610. If JIT is being used, but the JIT compilation is not being done immediately
  611. (perhaps waiting to see if the pattern is used often enough), similar logic is
  612. required. JIT compilation updates a value within the compiled code block, so a
  613. thread must gain unique write access to the pointer before calling
  614. \fBpcre2_jit_compile()\fP. Alternatively, \fBpcre2_code_copy()\fP or
  615. \fBpcre2_code_copy_with_tables()\fP can be used to obtain a private copy of the
  616. compiled code before calling the JIT compiler.
  617. .
  618. .
  619. .SS "Context blocks"
  620. .rs
  621. .sp
  622. The next main section below introduces the idea of "contexts" in which PCRE2
  623. functions are called. A context is nothing more than a collection of parameters
  624. that control the way PCRE2 operates. Grouping a number of parameters together
  625. in a context is a convenient way of passing them to a PCRE2 function without
  626. using lots of arguments. The parameters that are stored in contexts are in some
  627. sense "advanced features" of the API. Many straightforward applications will
  628. not need to use contexts.
  629. .P
  630. In a multithreaded application, if the parameters in a context are values that
  631. are never changed, the same context can be used by all the threads. However, if
  632. any thread needs to change any value in a context, it must make its own
  633. thread-specific copy.
  634. .
  635. .
  636. .SS "Match blocks"
  637. .rs
  638. .sp
  639. The matching functions need a block of memory for storing the results of a
  640. match. This includes details of what was matched, as well as additional
  641. information such as the name of a (*MARK) setting. Each thread must provide its
  642. own copy of this memory.
  643. .
  644. .
  645. .SH "PCRE2 CONTEXTS"
  646. .rs
  647. .sp
  648. Some PCRE2 functions have a lot of parameters, many of which are used only by
  649. specialist applications, for example, those that use custom memory management
  650. or non-standard character tables. To keep function argument lists at a
  651. reasonable size, and at the same time to keep the API extensible, "uncommon"
  652. parameters are passed to certain functions in a \fBcontext\fP instead of
  653. directly. A context is just a block of memory that holds the parameter values.
  654. Applications that do not need to adjust any of the context parameters can pass
  655. NULL when a context pointer is required.
  656. .P
  657. There are three different types of context: a general context that is relevant
  658. for several PCRE2 operations, a compile-time context, and a match-time context.
  659. .
  660. .
  661. .SS "The general context"
  662. .rs
  663. .sp
  664. At present, this context just contains pointers to (and data for) external
  665. memory management functions that are called from several places in the PCRE2
  666. library. The context is named `general' rather than specifically `memory'
  667. because in future other fields may be added. If you do not want to supply your
  668. own custom memory management functions, you do not need to bother with a
  669. general context. A general context is created by:
  670. .sp
  671. .nf
  672. .B pcre2_general_context *pcre2_general_context_create(
  673. .B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
  674. .B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
  675. .fi
  676. .sp
  677. The two function pointers specify custom memory management functions, whose
  678. prototypes are:
  679. .sp
  680. \fBvoid *private_malloc(PCRE2_SIZE, void *);\fP
  681. \fBvoid private_free(void *, void *);\fP
  682. .sp
  683. Whenever code in PCRE2 calls these functions, the final argument is the value
  684. of \fImemory_data\fP. Either of the first two arguments of the creation
  685. function may be NULL, in which case the system memory management functions
  686. \fImalloc()\fP and \fIfree()\fP are used. (This is not currently useful, as
  687. there are no other fields in a general context, but in future there might be.)
  688. The \fIprivate_malloc()\fP function is used (if supplied) to obtain memory for
  689. storing the context, and all three values are saved as part of the context.
  690. .P
  691. Whenever PCRE2 creates a data block of any kind, the block contains a pointer
  692. to the \fIfree()\fP function that matches the \fImalloc()\fP function that was
  693. used. When the time comes to free the block, this function is called.
  694. .P
  695. A general context can be copied by calling:
  696. .sp
  697. .nf
  698. .B pcre2_general_context *pcre2_general_context_copy(
  699. .B " pcre2_general_context *\fIgcontext\fP);"
  700. .fi
  701. .sp
  702. The memory used for a general context should be freed by calling:
  703. .sp
  704. .nf
  705. .B void pcre2_general_context_free(pcre2_general_context *\fIgcontext\fP);
  706. .fi
  707. .sp
  708. If this function is passed a NULL argument, it returns immediately without
  709. doing anything.
  710. .
  711. .
  712. .\" HTML <a name="compilecontext"></a>
  713. .SS "The compile context"
  714. .rs
  715. .sp
  716. A compile context is required if you want to provide an external function for
  717. stack checking during compilation or to change the default values of any of the
  718. following compile-time parameters:
  719. .sp
  720. What \eR matches (Unicode newlines or CR, LF, CRLF only)
  721. PCRE2's character tables
  722. The newline character sequence
  723. The compile time nested parentheses limit
  724. The maximum length of the pattern string
  725. The extra options bits (none set by default)
  726. .sp
  727. A compile context is also required if you are using custom memory management.
  728. If none of these apply, just pass NULL as the context argument of
  729. \fIpcre2_compile()\fP.
  730. .P
  731. A compile context is created, copied, and freed by the following functions:
  732. .sp
  733. .nf
  734. .B pcre2_compile_context *pcre2_compile_context_create(
  735. .B " pcre2_general_context *\fIgcontext\fP);"
  736. .sp
  737. .B pcre2_compile_context *pcre2_compile_context_copy(
  738. .B " pcre2_compile_context *\fIccontext\fP);"
  739. .sp
  740. .B void pcre2_compile_context_free(pcre2_compile_context *\fIccontext\fP);
  741. .fi
  742. .sp
  743. A compile context is created with default values for its parameters. These can
  744. be changed by calling the following functions, which return 0 on success, or
  745. PCRE2_ERROR_BADDATA if invalid data is detected.
  746. .sp
  747. .nf
  748. .B int pcre2_set_bsr(pcre2_compile_context *\fIccontext\fP,
  749. .B " uint32_t \fIvalue\fP);"
  750. .fi
  751. .sp
  752. The value must be PCRE2_BSR_ANYCRLF, to specify that \eR matches only CR, LF,
  753. or CRLF, or PCRE2_BSR_UNICODE, to specify that \eR matches any Unicode line
  754. ending sequence. The value is used by the JIT compiler and by the two
  755. interpreted matching functions, \fIpcre2_match()\fP and
  756. \fIpcre2_dfa_match()\fP.
  757. .sp
  758. .nf
  759. .B int pcre2_set_character_tables(pcre2_compile_context *\fIccontext\fP,
  760. .B " const uint8_t *\fItables\fP);"
  761. .fi
  762. .sp
  763. The value must be the result of a call to \fBpcre2_maketables()\fP, whose only
  764. argument is a general context. This function builds a set of character tables
  765. in the current locale.
  766. .sp
  767. .nf
  768. .B int pcre2_set_compile_extra_options(pcre2_compile_context *\fIccontext\fP,
  769. .B " uint32_t \fIextra_options\fP);"
  770. .fi
  771. .sp
  772. As PCRE2 has developed, almost all the 32 option bits that are available in
  773. the \fIoptions\fP argument of \fBpcre2_compile()\fP have been used up. To avoid
  774. running out, the compile context contains a set of extra option bits which are
  775. used for some newer, assumed rarer, options. This function sets those bits. It
  776. always sets all the bits (either on or off). It does not modify any existing
  777. setting. The available options are defined in the section entitled "Extra
  778. compile options"
  779. .\" HTML <a href="#extracompileoptions">
  780. .\" </a>
  781. below.
  782. .\"
  783. .sp
  784. .nf
  785. .B int pcre2_set_max_pattern_length(pcre2_compile_context *\fIccontext\fP,
  786. .B " PCRE2_SIZE \fIvalue\fP);"
  787. .fi
  788. .sp
  789. This sets a maximum length, in code units, for any pattern string that is
  790. compiled with this context. If the pattern is longer, an error is generated.
  791. This facility is provided so that applications that accept patterns from
  792. external sources can limit their size. The default is the largest number that a
  793. PCRE2_SIZE variable can hold, which is effectively unlimited.
  794. .sp
  795. .nf
  796. .B int pcre2_set_newline(pcre2_compile_context *\fIccontext\fP,
  797. .B " uint32_t \fIvalue\fP);"
  798. .fi
  799. .sp
  800. This specifies which characters or character sequences are to be recognized as
  801. newlines. The value must be one of PCRE2_NEWLINE_CR (carriage return only),
  802. PCRE2_NEWLINE_LF (linefeed only), PCRE2_NEWLINE_CRLF (the two-character
  803. sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any of the above),
  804. PCRE2_NEWLINE_ANY (any Unicode newline sequence), or PCRE2_NEWLINE_NUL (the
  805. NUL character, that is a binary zero).
  806. .P
  807. A pattern can override the value set in the compile context by starting with a
  808. sequence such as (*CRLF). See the
  809. .\" HREF
  810. \fBpcre2pattern\fP
  811. .\"
  812. page for details.
  813. .P
  814. When a pattern is compiled with the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE
  815. option, the newline convention affects the recognition of the end of internal
  816. comments starting with #. The value is saved with the compiled pattern for
  817. subsequent use by the JIT compiler and by the two interpreted matching
  818. functions, \fIpcre2_match()\fP and \fIpcre2_dfa_match()\fP.
  819. .sp
  820. .nf
  821. .B int pcre2_set_parens_nest_limit(pcre2_compile_context *\fIccontext\fP,
  822. .B " uint32_t \fIvalue\fP);"
  823. .fi
  824. .sp
  825. This parameter adjusts the limit, set when PCRE2 is built (default 250), on the
  826. depth of parenthesis nesting in a pattern. This limit stops rogue patterns
  827. using up too much system stack when being compiled. The limit applies to
  828. parentheses of all kinds, not just capturing parentheses.
  829. .sp
  830. .nf
  831. .B int pcre2_set_compile_recursion_guard(pcre2_compile_context *\fIccontext\fP,
  832. .B " int (*\fIguard_function\fP)(uint32_t, void *), void *\fIuser_data\fP);"
  833. .fi
  834. .sp
  835. There is at least one application that runs PCRE2 in threads with very limited
  836. system stack, where running out of stack is to be avoided at all costs. The
  837. parenthesis limit above cannot take account of how much stack is actually
  838. available during compilation. For a finer control, you can supply a function
  839. that is called whenever \fBpcre2_compile()\fP starts to compile a parenthesized
  840. part of a pattern. This function can check the actual stack size (or anything
  841. else that it wants to, of course).
  842. .P
  843. The first argument to the callout function gives the current depth of
  844. nesting, and the second is user data that is set up by the last argument of
  845. \fBpcre2_set_compile_recursion_guard()\fP. The callout function should return
  846. zero if all is well, or non-zero to force an error.
  847. .
  848. .
  849. .\" HTML <a name="matchcontext"></a>
  850. .SS "The match context"
  851. .rs
  852. .sp
  853. A match context is required if you want to:
  854. .sp
  855. Set up a callout function
  856. Set an offset limit for matching an unanchored pattern
  857. Change the limit on the amount of heap used when matching
  858. Change the backtracking match limit
  859. Change the backtracking depth limit
  860. Set custom memory management specifically for the match
  861. .sp
  862. If none of these apply, just pass NULL as the context argument of
  863. \fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or \fBpcre2_jit_match()\fP.
  864. .P
  865. A match context is created, copied, and freed by the following functions:
  866. .sp
  867. .nf
  868. .B pcre2_match_context *pcre2_match_context_create(
  869. .B " pcre2_general_context *\fIgcontext\fP);"
  870. .sp
  871. .B pcre2_match_context *pcre2_match_context_copy(
  872. .B " pcre2_match_context *\fImcontext\fP);"
  873. .sp
  874. .B void pcre2_match_context_free(pcre2_match_context *\fImcontext\fP);
  875. .fi
  876. .sp
  877. A match context is created with default values for its parameters. These can
  878. be changed by calling the following functions, which return 0 on success, or
  879. PCRE2_ERROR_BADDATA if invalid data is detected.
  880. .sp
  881. .nf
  882. .B int pcre2_set_callout(pcre2_match_context *\fImcontext\fP,
  883. .B " int (*\fIcallout_function\fP)(pcre2_callout_block *, void *),"
  884. .B " void *\fIcallout_data\fP);"
  885. .fi
  886. .sp
  887. This sets up a callout function for PCRE2 to call at specified points
  888. during a matching operation. Details are given in the
  889. .\" HREF
  890. \fBpcre2callout\fP
  891. .\"
  892. documentation.
  893. .sp
  894. .nf
  895. .B int pcre2_set_substitute_callout(pcre2_match_context *\fImcontext\fP,
  896. .B " int (*\fIcallout_function\fP)(pcre2_substitute_callout_block *, void *),"
  897. .B " void *\fIcallout_data\fP);"
  898. .fi
  899. .sp
  900. This sets up a callout function for PCRE2 to call after each substitution
  901. made by \fBpcre2_substitute()\fP. Details are given in the section entitled
  902. "Creating a new string with substitutions"
  903. .\" HTML <a href="#substitutions">
  904. .\" </a>
  905. below.
  906. .\"
  907. .sp
  908. .nf
  909. .B int pcre2_set_offset_limit(pcre2_match_context *\fImcontext\fP,
  910. .B " PCRE2_SIZE \fIvalue\fP);"
  911. .fi
  912. .sp
  913. The \fIoffset_limit\fP parameter limits how far an unanchored search can
  914. advance in the subject string. The default value is PCRE2_UNSET. The
  915. \fBpcre2_match()\fP and \fBpcre2_dfa_match()\fP functions return
  916. PCRE2_ERROR_NOMATCH if a match with a starting point before or at the given
  917. offset is not found. The \fBpcre2_substitute()\fP function makes no more
  918. substitutions.
  919. .P
  920. For example, if the pattern /abc/ is matched against "123abc" with an offset
  921. limit less than 3, the result is PCRE2_ERROR_NOMATCH. A match can never be
  922. found if the \fIstartoffset\fP argument of \fBpcre2_match()\fP,
  923. \fBpcre2_dfa_match()\fP, or \fBpcre2_substitute()\fP is greater than the offset
  924. limit set in the match context.
  925. .P
  926. When using this facility, you must set the PCRE2_USE_OFFSET_LIMIT option when
  927. calling \fBpcre2_compile()\fP so that when JIT is in use, different code can be
  928. compiled. If a match is started with a non-default match limit when
  929. PCRE2_USE_OFFSET_LIMIT is not set, an error is generated.
  930. .P
  931. The offset limit facility can be used to track progress when searching large
  932. subject strings or to limit the extent of global substitutions. See also the
  933. PCRE2_FIRSTLINE option, which requires a match to start before or at the first
  934. newline that follows the start of matching in the subject. If this is set with
  935. an offset limit, a match must occur in the first line and also within the
  936. offset limit. In other words, whichever limit comes first is used.
  937. .sp
  938. .nf
  939. .B int pcre2_set_heap_limit(pcre2_match_context *\fImcontext\fP,
  940. .B " uint32_t \fIvalue\fP);"
  941. .fi
  942. .sp
  943. The \fIheap_limit\fP parameter specifies, in units of kibibytes (1024 bytes),
  944. the maximum amount of heap memory that \fBpcre2_match()\fP may use to hold
  945. backtracking information when running an interpretive match. This limit also
  946. applies to \fBpcre2_dfa_match()\fP, which may use the heap when processing
  947. patterns with a lot of nested pattern recursion or lookarounds or atomic
  948. groups. This limit does not apply to matching with the JIT optimization, which
  949. has its own memory control arrangements (see the
  950. .\" HREF
  951. \fBpcre2jit\fP
  952. .\"
  953. documentation for more details). If the limit is reached, the negative error
  954. code PCRE2_ERROR_HEAPLIMIT is returned. The default limit can be set when PCRE2
  955. is built; if it is not, the default is set very large and is essentially
  956. "unlimited".
  957. .P
  958. A value for the heap limit may also be supplied by an item at the start of a
  959. pattern of the form
  960. .sp
  961. (*LIMIT_HEAP=ddd)
  962. .sp
  963. where ddd is a decimal number. However, such a setting is ignored unless ddd is
  964. less than the limit set by the caller of \fBpcre2_match()\fP or, if no such
  965. limit is set, less than the default.
  966. .P
  967. The \fBpcre2_match()\fP function starts out using a 20KiB vector on the system
  968. stack for recording backtracking points. The more nested backtracking points
  969. there are (that is, the deeper the search tree), the more memory is needed.
  970. Heap memory is used only if the initial vector is too small. If the heap limit
  971. is set to a value less than 21 (in particular, zero) no heap memory will be
  972. used. In this case, only patterns that do not have a lot of nested backtracking
  973. can be successfully processed.
  974. .P
  975. Similarly, for \fBpcre2_dfa_match()\fP, a vector on the system stack is used
  976. when processing pattern recursions, lookarounds, or atomic groups, and only if
  977. this is not big enough is heap memory used. In this case, too, setting a value
  978. of zero disables the use of the heap.
  979. .sp
  980. .nf
  981. .B int pcre2_set_match_limit(pcre2_match_context *\fImcontext\fP,
  982. .B " uint32_t \fIvalue\fP);"
  983. .fi
  984. .sp
  985. The \fImatch_limit\fP parameter provides a means of preventing PCRE2 from using
  986. up too many computing resources when processing patterns that are not going to
  987. match, but which have a very large number of possibilities in their search
  988. trees. The classic example is a pattern that uses nested unlimited repeats.
  989. .P
  990. There is an internal counter in \fBpcre2_match()\fP that is incremented each
  991. time round its main matching loop. If this value reaches the match limit,
  992. \fBpcre2_match()\fP returns the negative value PCRE2_ERROR_MATCHLIMIT. This has
  993. the effect of limiting the amount of backtracking that can take place. For
  994. patterns that are not anchored, the count restarts from zero for each position
  995. in the subject string. This limit also applies to \fBpcre2_dfa_match()\fP,
  996. though the counting is done in a different way.
  997. .P
  998. When \fBpcre2_match()\fP is called with a pattern that was successfully
  999. processed by \fBpcre2_jit_compile()\fP, the way in which matching is executed
  1000. is entirely different. However, there is still the possibility of runaway
  1001. matching that goes on for a very long time, and so the \fImatch_limit\fP value
  1002. is also used in this case (but in a different way) to limit how long the
  1003. matching can continue.
  1004. .P
  1005. The default value for the limit can be set when PCRE2 is built; the default
  1006. default is 10 million, which handles all but the most extreme cases. A value
  1007. for the match limit may also be supplied by an item at the start of a pattern
  1008. of the form
  1009. .sp
  1010. (*LIMIT_MATCH=ddd)
  1011. .sp
  1012. where ddd is a decimal number. However, such a setting is ignored unless ddd is
  1013. less than the limit set by the caller of \fBpcre2_match()\fP or
  1014. \fBpcre2_dfa_match()\fP or, if no such limit is set, less than the default.
  1015. .sp
  1016. .nf
  1017. .B int pcre2_set_depth_limit(pcre2_match_context *\fImcontext\fP,
  1018. .B " uint32_t \fIvalue\fP);"
  1019. .fi
  1020. .sp
  1021. This parameter limits the depth of nested backtracking in \fBpcre2_match()\fP.
  1022. Each time a nested backtracking point is passed, a new memory "frame" is used
  1023. to remember the state of matching at that point. Thus, this parameter
  1024. indirectly limits the amount of memory that is used in a match. However,
  1025. because the size of each memory "frame" depends on the number of capturing
  1026. parentheses, the actual memory limit varies from pattern to pattern. This limit
  1027. was more useful in versions before 10.30, where function recursion was used for
  1028. backtracking.
  1029. .P
  1030. The depth limit is not relevant, and is ignored, when matching is done using
  1031. JIT compiled code. However, it is supported by \fBpcre2_dfa_match()\fP, which
  1032. uses it to limit the depth of nested internal recursive function calls that
  1033. implement atomic groups, lookaround assertions, and pattern recursions. This
  1034. limits, indirectly, the amount of system stack that is used. It was more useful
  1035. in versions before 10.32, when stack memory was used for local workspace
  1036. vectors for recursive function calls. From version 10.32, only local variables
  1037. are allocated on the stack and as each call uses only a few hundred bytes, even
  1038. a small stack can support quite a lot of recursion.
  1039. .P
  1040. If the depth of internal recursive function calls is great enough, local
  1041. workspace vectors are allocated on the heap from version 10.32 onwards, so the
  1042. depth limit also indirectly limits the amount of heap memory that is used. A
  1043. recursive pattern such as /(.(?2))((?1)|)/, when matched to a very long string
  1044. using \fBpcre2_dfa_match()\fP, can use a great deal of memory. However, it is
  1045. probably better to limit heap usage directly by calling
  1046. \fBpcre2_set_heap_limit()\fP.
  1047. .P
  1048. The default value for the depth limit can be set when PCRE2 is built; if it is
  1049. not, the default is set to the same value as the default for the match limit.
  1050. If the limit is exceeded, \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP
  1051. returns PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be
  1052. supplied by an item at the start of a pattern of the form
  1053. .sp
  1054. (*LIMIT_DEPTH=ddd)
  1055. .sp
  1056. where ddd is a decimal number. However, such a setting is ignored unless ddd is
  1057. less than the limit set by the caller of \fBpcre2_match()\fP or
  1058. \fBpcre2_dfa_match()\fP or, if no such limit is set, less than the default.
  1059. .
  1060. .
  1061. .SH "CHECKING BUILD-TIME OPTIONS"
  1062. .rs
  1063. .sp
  1064. .B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP);
  1065. .P
  1066. The function \fBpcre2_config()\fP makes it possible for a PCRE2 client to find
  1067. the value of certain configuration parameters and to discover which optional
  1068. features have been compiled into the PCRE2 library. The
  1069. .\" HREF
  1070. \fBpcre2build\fP
  1071. .\"
  1072. documentation has more details about these features.
  1073. .P
  1074. The first argument for \fBpcre2_config()\fP specifies which information is
  1075. required. The second argument is a pointer to memory into which the information
  1076. is placed. If NULL is passed, the function returns the amount of memory that is
  1077. needed for the requested information. For calls that return numerical values,
  1078. the value is in bytes; when requesting these values, \fIwhere\fP should point
  1079. to appropriately aligned memory. For calls that return strings, the required
  1080. length is given in code units, not counting the terminating zero.
  1081. .P
  1082. When requesting information, the returned value from \fBpcre2_config()\fP is
  1083. non-negative on success, or the negative error code PCRE2_ERROR_BADOPTION if
  1084. the value in the first argument is not recognized. The following information is
  1085. available:
  1086. .sp
  1087. PCRE2_CONFIG_BSR
  1088. .sp
  1089. The output is a uint32_t integer whose value indicates what character
  1090. sequences the \eR escape sequence matches by default. A value of
  1091. PCRE2_BSR_UNICODE means that \eR matches any Unicode line ending sequence; a
  1092. value of PCRE2_BSR_ANYCRLF means that \eR matches only CR, LF, or CRLF. The
  1093. default can be overridden when a pattern is compiled.
  1094. .sp
  1095. PCRE2_CONFIG_COMPILED_WIDTHS
  1096. .sp
  1097. The output is a uint32_t integer whose lower bits indicate which code unit
  1098. widths were selected when PCRE2 was built. The 1-bit indicates 8-bit support,
  1099. and the 2-bit and 4-bit indicate 16-bit and 32-bit support, respectively.
  1100. .sp
  1101. PCRE2_CONFIG_DEPTHLIMIT
  1102. .sp
  1103. The output is a uint32_t integer that gives the default limit for the depth of
  1104. nested backtracking in \fBpcre2_match()\fP or the depth of nested recursions,
  1105. lookarounds, and atomic groups in \fBpcre2_dfa_match()\fP. Further details are
  1106. given with \fBpcre2_set_depth_limit()\fP above.
  1107. .sp
  1108. PCRE2_CONFIG_HEAPLIMIT
  1109. .sp
  1110. The output is a uint32_t integer that gives, in kibibytes, the default limit
  1111. for the amount of heap memory used by \fBpcre2_match()\fP or
  1112. \fBpcre2_dfa_match()\fP. Further details are given with
  1113. \fBpcre2_set_heap_limit()\fP above.
  1114. .sp
  1115. PCRE2_CONFIG_JIT
  1116. .sp
  1117. The output is a uint32_t integer that is set to one if support for just-in-time
  1118. compiling is available; otherwise it is set to zero.
  1119. .sp
  1120. PCRE2_CONFIG_JITTARGET
  1121. .sp
  1122. The \fIwhere\fP argument should point to a buffer that is at least 48 code
  1123. units long. (The exact length required can be found by calling
  1124. \fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a
  1125. string that contains the name of the architecture for which the JIT compiler is
  1126. configured, for example "x86 32bit (little endian + unaligned)". If JIT support
  1127. is not available, PCRE2_ERROR_BADOPTION is returned, otherwise the number of
  1128. code units used is returned. This is the length of the string, plus one unit
  1129. for the terminating zero.
  1130. .sp
  1131. PCRE2_CONFIG_LINKSIZE
  1132. .sp
  1133. The output is a uint32_t integer that contains the number of bytes used for
  1134. internal linkage in compiled regular expressions. When PCRE2 is configured, the
  1135. value can be set to 2, 3, or 4, with the default being 2. This is the value
  1136. that is returned by \fBpcre2_config()\fP. However, when the 16-bit library is
  1137. compiled, a value of 3 is rounded up to 4, and when the 32-bit library is
  1138. compiled, internal linkages always use 4 bytes, so the configured value is not
  1139. relevant.
  1140. .P
  1141. The default value of 2 for the 8-bit and 16-bit libraries is sufficient for all
  1142. but the most massive patterns, since it allows the size of the compiled pattern
  1143. to be up to 65535 code units. Larger values allow larger regular expressions to
  1144. be compiled by those two libraries, but at the expense of slower matching.
  1145. .sp
  1146. PCRE2_CONFIG_MATCHLIMIT
  1147. .sp
  1148. The output is a uint32_t integer that gives the default match limit for
  1149. \fBpcre2_match()\fP. Further details are given with
  1150. \fBpcre2_set_match_limit()\fP above.
  1151. .sp
  1152. PCRE2_CONFIG_NEWLINE
  1153. .sp
  1154. The output is a uint32_t integer whose value specifies the default character
  1155. sequence that is recognized as meaning "newline". The values are:
  1156. .sp
  1157. PCRE2_NEWLINE_CR Carriage return (CR)
  1158. PCRE2_NEWLINE_LF Linefeed (LF)
  1159. PCRE2_NEWLINE_CRLF Carriage return, linefeed (CRLF)
  1160. PCRE2_NEWLINE_ANY Any Unicode line ending
  1161. PCRE2_NEWLINE_ANYCRLF Any of CR, LF, or CRLF
  1162. PCRE2_NEWLINE_NUL The NUL character (binary zero)
  1163. .sp
  1164. The default should normally correspond to the standard sequence for your
  1165. operating system.
  1166. .sp
  1167. PCRE2_CONFIG_NEVER_BACKSLASH_C
  1168. .sp
  1169. The output is a uint32_t integer that is set to one if the use of \eC was
  1170. permanently disabled when PCRE2 was built; otherwise it is set to zero.
  1171. .sp
  1172. PCRE2_CONFIG_PARENSLIMIT
  1173. .sp
  1174. The output is a uint32_t integer that gives the maximum depth of nesting
  1175. of parentheses (of any kind) in a pattern. This limit is imposed to cap the
  1176. amount of system stack used when a pattern is compiled. It is specified when
  1177. PCRE2 is built; the default is 250. This limit does not take into account the
  1178. stack that may already be used by the calling application. For finer control
  1179. over compilation stack usage, see \fBpcre2_set_compile_recursion_guard()\fP.
  1180. .sp
  1181. PCRE2_CONFIG_STACKRECURSE
  1182. .sp
  1183. This parameter is obsolete and should not be used in new code. The output is a
  1184. uint32_t integer that is always set to zero.
  1185. .sp
  1186. PCRE2_CONFIG_TABLES_LENGTH
  1187. .sp
  1188. The output is a uint32_t integer that gives the length of PCRE2's character
  1189. processing tables in bytes. For details of these tables see the
  1190. .\" HTML <a href="#localesupport">
  1191. .\" </a>
  1192. section on locale support
  1193. .\"
  1194. below.
  1195. .sp
  1196. PCRE2_CONFIG_UNICODE_VERSION
  1197. .sp
  1198. The \fIwhere\fP argument should point to a buffer that is at least 24 code
  1199. units long. (The exact length required can be found by calling
  1200. \fBpcre2_config()\fP with \fBwhere\fP set to NULL.) If PCRE2 has been compiled
  1201. without Unicode support, the buffer is filled with the text "Unicode not
  1202. supported". Otherwise, the Unicode version string (for example, "8.0.0") is
  1203. inserted. The number of code units used is returned. This is the length of the
  1204. string plus one unit for the terminating zero.
  1205. .sp
  1206. PCRE2_CONFIG_UNICODE
  1207. .sp
  1208. The output is a uint32_t integer that is set to one if Unicode support is
  1209. available; otherwise it is set to zero. Unicode support implies UTF support.
  1210. .sp
  1211. PCRE2_CONFIG_VERSION
  1212. .sp
  1213. The \fIwhere\fP argument should point to a buffer that is at least 24 code
  1214. units long. (The exact length required can be found by calling
  1215. \fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with
  1216. the PCRE2 version string, zero-terminated. The number of code units used is
  1217. returned. This is the length of the string plus one unit for the terminating
  1218. zero.
  1219. .
  1220. .
  1221. .\" HTML <a name="compiling"></a>
  1222. .SH "COMPILING A PATTERN"
  1223. .rs
  1224. .sp
  1225. .nf
  1226. .B pcre2_code *pcre2_compile(PCRE2_SPTR \fIpattern\fP, PCRE2_SIZE \fIlength\fP,
  1227. .B " uint32_t \fIoptions\fP, int *\fIerrorcode\fP, PCRE2_SIZE *\fIerroroffset,\fP"
  1228. .B " pcre2_compile_context *\fIccontext\fP);"
  1229. .sp
  1230. .B void pcre2_code_free(pcre2_code *\fIcode\fP);
  1231. .sp
  1232. .B pcre2_code *pcre2_code_copy(const pcre2_code *\fIcode\fP);
  1233. .sp
  1234. .B pcre2_code *pcre2_code_copy_with_tables(const pcre2_code *\fIcode\fP);
  1235. .fi
  1236. .P
  1237. The \fBpcre2_compile()\fP function compiles a pattern into an internal form.
  1238. The pattern is defined by a pointer to a string of code units and a length (in
  1239. code units). If the pattern is zero-terminated, the length can be specified as
  1240. PCRE2_ZERO_TERMINATED. The function returns a pointer to a block of memory that
  1241. contains the compiled pattern and related data, or NULL if an error occurred.
  1242. .P
  1243. If the compile context argument \fIccontext\fP is NULL, memory for the compiled
  1244. pattern is obtained by calling \fBmalloc()\fP. Otherwise, it is obtained from
  1245. the same memory function that was used for the compile context. The caller must
  1246. free the memory by calling \fBpcre2_code_free()\fP when it is no longer needed.
  1247. If \fBpcre2_code_free()\fP is called with a NULL argument, it returns
  1248. immediately, without doing anything.
  1249. .P
  1250. The function \fBpcre2_code_copy()\fP makes a copy of the compiled code in new
  1251. memory, using the same memory allocator as was used for the original. However,
  1252. if the code has been processed by the JIT compiler (see
  1253. .\" HTML <a href="#jitcompiling">
  1254. .\" </a>
  1255. below),
  1256. .\"
  1257. the JIT information cannot be copied (because it is position-dependent).
  1258. The new copy can initially be used only for non-JIT matching, though it can be
  1259. passed to \fBpcre2_jit_compile()\fP if required. If \fBpcre2_code_copy()\fP is
  1260. called with a NULL argument, it returns NULL.
  1261. .P
  1262. The \fBpcre2_code_copy()\fP function provides a way for individual threads in a
  1263. multithreaded application to acquire a private copy of shared compiled code.
  1264. However, it does not make a copy of the character tables used by the compiled
  1265. pattern; the new pattern code points to the same tables as the original code.
  1266. (See
  1267. .\" HTML <a href="#jitcompiling">
  1268. .\" </a>
  1269. "Locale Support"
  1270. .\"
  1271. below for details of these character tables.) In many applications the same
  1272. tables are used throughout, so this behaviour is appropriate. Nevertheless,
  1273. there are occasions when a copy of a compiled pattern and the relevant tables
  1274. are needed. The \fBpcre2_code_copy_with_tables()\fP provides this facility.
  1275. Copies of both the code and the tables are made, with the new code pointing to
  1276. the new tables. The memory for the new tables is automatically freed when
  1277. \fBpcre2_code_free()\fP is called for the new copy of the compiled code. If
  1278. \fBpcre2_code_copy_with_tables()\fP is called with a NULL argument, it returns
  1279. NULL.
  1280. .P
  1281. NOTE: When one of the matching functions is called, pointers to the compiled
  1282. pattern and the subject string are set in the match data block so that they can
  1283. be referenced by the substring extraction functions after a successful match.
  1284. After running a match, you must not free a compiled pattern or a subject string
  1285. until after all operations on the
  1286. .\" HTML <a href="#matchdatablock">
  1287. .\" </a>
  1288. match data block
  1289. .\"
  1290. have taken place, unless, in the case of the subject string, you have used the
  1291. PCRE2_COPY_MATCHED_SUBJECT option, which is described in the section entitled
  1292. "Option bits for \fBpcre2_match()\fP"
  1293. .\" HTML <a href="#matchoptions>">
  1294. .\" </a>
  1295. below.
  1296. .\"
  1297. .P
  1298. The \fIoptions\fP argument for \fBpcre2_compile()\fP contains various bit
  1299. settings that affect the compilation. It should be zero if none of them are
  1300. required. The available options are described below. Some of them (in
  1301. particular, those that are compatible with Perl, but some others as well) can
  1302. also be set and unset from within the pattern (see the detailed description in
  1303. the
  1304. .\" HREF
  1305. \fBpcre2pattern\fP
  1306. .\"
  1307. documentation).
  1308. .P
  1309. For those options that can be different in different parts of the pattern, the
  1310. contents of the \fIoptions\fP argument specifies their settings at the start of
  1311. compilation. The PCRE2_ANCHORED, PCRE2_ENDANCHORED, and PCRE2_NO_UTF_CHECK
  1312. options can be set at the time of matching as well as at compile time.
  1313. .P
  1314. Some additional options and less frequently required compile-time parameters
  1315. (for example, the newline setting) can be provided in a compile context (as
  1316. described
  1317. .\" HTML <a href="#compilecontext">
  1318. .\" </a>
  1319. above).
  1320. .\"
  1321. .P
  1322. If \fIerrorcode\fP or \fIerroroffset\fP is NULL, \fBpcre2_compile()\fP returns
  1323. NULL immediately. Otherwise, the variables to which these point are set to an
  1324. error code and an offset (number of code units) within the pattern,
  1325. respectively, when \fBpcre2_compile()\fP returns NULL because a compilation
  1326. error has occurred. The values are not defined when compilation is successful
  1327. and \fBpcre2_compile()\fP returns a non-NULL value.
  1328. .P
  1329. There are nearly 100 positive error codes that \fBpcre2_compile()\fP may return
  1330. if it finds an error in the pattern. There are also some negative error codes
  1331. that are used for invalid UTF strings when validity checking is in force. These
  1332. are the same as given by \fBpcre2_match()\fP and \fBpcre2_dfa_match()\fP, and
  1333. are described in the
  1334. .\" HREF
  1335. \fBpcre2unicode\fP
  1336. .\"
  1337. documentation. There is no separate documentation for the positive error codes,
  1338. because the textual error messages that are obtained by calling the
  1339. \fBpcre2_get_error_message()\fP function (see "Obtaining a textual error
  1340. message"
  1341. .\" HTML <a href="#geterrormessage">
  1342. .\" </a>
  1343. below)
  1344. .\"
  1345. should be self-explanatory. Macro names starting with PCRE2_ERROR_ are defined
  1346. for both positive and negative error codes in \fBpcre2.h\fP.
  1347. .P
  1348. The value returned in \fIerroroffset\fP is an indication of where in the
  1349. pattern the error occurred. It is not necessarily the furthest point in the
  1350. pattern that was read. For example, after the error "lookbehind assertion is
  1351. not fixed length", the error offset points to the start of the failing
  1352. assertion. For an invalid UTF-8 or UTF-16 string, the offset is that of the
  1353. first code unit of the failing character.
  1354. .P
  1355. Some errors are not detected until the whole pattern has been scanned; in these
  1356. cases, the offset passed back is the length of the pattern. Note that the
  1357. offset is in code units, not characters, even in a UTF mode. It may sometimes
  1358. point into the middle of a UTF-8 or UTF-16 character.
  1359. .P
  1360. This code fragment shows a typical straightforward call to
  1361. \fBpcre2_compile()\fP:
  1362. .sp
  1363. pcre2_code *re;
  1364. PCRE2_SIZE erroffset;
  1365. int errorcode;
  1366. re = pcre2_compile(
  1367. "^A.*Z", /* the pattern */
  1368. PCRE2_ZERO_TERMINATED, /* the pattern is zero-terminated */
  1369. 0, /* default options */
  1370. &errorcode, /* for error code */
  1371. &erroffset, /* for error offset */
  1372. NULL); /* no compile context */
  1373. .sp
  1374. .
  1375. .
  1376. .SS "Main compile options"
  1377. .rs
  1378. .sp
  1379. The following names for option bits are defined in the \fBpcre2.h\fP header
  1380. file:
  1381. .sp
  1382. PCRE2_ANCHORED
  1383. .sp
  1384. If this bit is set, the pattern is forced to be "anchored", that is, it is
  1385. constrained to match only at the first matching point in the string that is
  1386. being searched (the "subject string"). This effect can also be achieved by
  1387. appropriate constructs in the pattern itself, which is the only way to do it in
  1388. Perl.
  1389. .sp
  1390. PCRE2_ALLOW_EMPTY_CLASS
  1391. .sp
  1392. By default, for compatibility with Perl, a closing square bracket that
  1393. immediately follows an opening one is treated as a data character for the
  1394. class. When PCRE2_ALLOW_EMPTY_CLASS is set, it terminates the class, which
  1395. therefore contains no characters and so can never match.
  1396. .sp
  1397. PCRE2_ALT_BSUX
  1398. .sp
  1399. This option request alternative handling of three escape sequences, which
  1400. makes PCRE2's behaviour more like ECMAscript (aka JavaScript). When it is set:
  1401. .P
  1402. (1) \eU matches an upper case "U" character; by default \eU causes a compile
  1403. time error (Perl uses \eU to upper case subsequent characters).
  1404. .P
  1405. (2) \eu matches a lower case "u" character unless it is followed by four
  1406. hexadecimal digits, in which case the hexadecimal number defines the code point
  1407. to match. By default, \eu causes a compile time error (Perl uses it to upper
  1408. case the following character).
  1409. .P
  1410. (3) \ex matches a lower case "x" character unless it is followed by two
  1411. hexadecimal digits, in which case the hexadecimal number defines the code point
  1412. to match. By default, as in Perl, a hexadecimal number is always expected after
  1413. \ex, but it may have zero, one, or two digits (so, for example, \exz matches a
  1414. binary zero character followed by z).
  1415. .P
  1416. ECMAscript 6 added additional functionality to \eu. This can be accessed using
  1417. the PCRE2_EXTRA_ALT_BSUX extra option (see "Extra compile options"
  1418. .\" HTML <a href="#extracompileoptions">
  1419. .\" </a>
  1420. below).
  1421. .\"
  1422. Note that this alternative escape handling applies only to patterns. Neither of
  1423. these options affects the processing of replacement strings passed to
  1424. \fBpcre2_substitute()\fP.
  1425. .sp
  1426. PCRE2_ALT_CIRCUMFLEX
  1427. .sp
  1428. In multiline mode (when PCRE2_MULTILINE is set), the circumflex metacharacter
  1429. matches at the start of the subject (unless PCRE2_NOTBOL is set), and also
  1430. after any internal newline. However, it does not match after a newline at the
  1431. end of the subject, for compatibility with Perl. If you want a multiline
  1432. circumflex also to match after a terminating newline, you must set
  1433. PCRE2_ALT_CIRCUMFLEX.
  1434. .sp
  1435. PCRE2_ALT_VERBNAMES
  1436. .sp
  1437. By default, for compatibility with Perl, the name in any verb sequence such as
  1438. (*MARK:NAME) is any sequence of characters that does not include a closing
  1439. parenthesis. The name is not processed in any way, and it is not possible to
  1440. include a closing parenthesis in the name. However, if the PCRE2_ALT_VERBNAMES
  1441. option is set, normal backslash processing is applied to verb names and only an
  1442. unescaped closing parenthesis terminates the name. A closing parenthesis can be
  1443. included in a name either as \e) or between \eQ and \eE. If the PCRE2_EXTENDED
  1444. or PCRE2_EXTENDED_MORE option is set with PCRE2_ALT_VERBNAMES, unescaped
  1445. whitespace in verb names is skipped and #-comments are recognized, exactly as
  1446. in the rest of the pattern.
  1447. .sp
  1448. PCRE2_AUTO_CALLOUT
  1449. .sp
  1450. If this bit is set, \fBpcre2_compile()\fP automatically inserts callout items,
  1451. all with number 255, before each pattern item, except immediately before or
  1452. after an explicit callout in the pattern. For discussion of the callout
  1453. facility, see the
  1454. .\" HREF
  1455. \fBpcre2callout\fP
  1456. .\"
  1457. documentation.
  1458. .sp
  1459. PCRE2_CASELESS
  1460. .sp
  1461. If this bit is set, letters in the pattern match both upper and lower case
  1462. letters in the subject. It is equivalent to Perl's /i option, and it can be
  1463. changed within a pattern by a (?i) option setting. If either PCRE2_UTF or
  1464. PCRE2_UCP is set, Unicode properties are used for all characters with more than
  1465. one other case, and for all characters whose code points are greater than
  1466. U+007F. Note that there are two ASCII characters, K and S, that, in addition to
  1467. their lower case ASCII equivalents, are case-equivalent with U+212A (Kelvin
  1468. sign) and U+017F (long S) respectively. For lower valued characters with only
  1469. one other case, a lookup table is used for speed. When neither PCRE2_UTF nor
  1470. PCRE2_UCP is set, a lookup table is used for all code points less than 256, and
  1471. higher code points (available only in 16-bit or 32-bit mode) are treated as not
  1472. having another case.
  1473. .sp
  1474. PCRE2_DOLLAR_ENDONLY
  1475. .sp
  1476. If this bit is set, a dollar metacharacter in the pattern matches only at the
  1477. end of the subject string. Without this option, a dollar also matches
  1478. immediately before a newline at the end of the string (but not before any other
  1479. newlines). The PCRE2_DOLLAR_ENDONLY option is ignored if PCRE2_MULTILINE is
  1480. set. There is no equivalent to this option in Perl, and no way to set it within
  1481. a pattern.
  1482. .sp
  1483. PCRE2_DOTALL
  1484. .sp
  1485. If this bit is set, a dot metacharacter in the pattern matches any character,
  1486. including one that indicates a newline. However, it only ever matches one
  1487. character, even if newlines are coded as CRLF. Without this option, a dot does
  1488. not match when the current position in the subject is at a newline. This option
  1489. is equivalent to Perl's /s option, and it can be changed within a pattern by a
  1490. (?s) option setting. A negative class such as [^a] always matches newline
  1491. characters, and the \eN escape sequence always matches a non-newline character,
  1492. independent of the setting of PCRE2_DOTALL.
  1493. .sp
  1494. PCRE2_DUPNAMES
  1495. .sp
  1496. If this bit is set, names used to identify capture groups need not be unique.
  1497. This can be helpful for certain types of pattern when it is known that only one
  1498. instance of the named group can ever be matched. There are more details of
  1499. named capture groups below; see also the
  1500. .\" HREF
  1501. \fBpcre2pattern\fP
  1502. .\"
  1503. documentation.
  1504. .sp
  1505. PCRE2_ENDANCHORED
  1506. .sp
  1507. If this bit is set, the end of any pattern match must be right at the end of
  1508. the string being searched (the "subject string"). If the pattern match
  1509. succeeds by reaching (*ACCEPT), but does not reach the end of the subject, the
  1510. match fails at the current starting point. For unanchored patterns, a new match
  1511. is then tried at the next starting point. However, if the match succeeds by
  1512. reaching the end of the pattern, but not the end of the subject, backtracking
  1513. occurs and an alternative match may be found. Consider these two patterns:
  1514. .sp
  1515. .(*ACCEPT)|..
  1516. .|..
  1517. .sp
  1518. If matched against "abc" with PCRE2_ENDANCHORED set, the first matches "c"
  1519. whereas the second matches "bc". The effect of PCRE2_ENDANCHORED can also be
  1520. achieved by appropriate constructs in the pattern itself, which is the only way
  1521. to do it in Perl.
  1522. .P
  1523. For DFA matching with \fBpcre2_dfa_match()\fP, PCRE2_ENDANCHORED applies only
  1524. to the first (that is, the longest) matched string. Other parallel matches,
  1525. which are necessarily substrings of the first one, must obviously end before
  1526. the end of the subject.
  1527. .sp
  1528. PCRE2_EXTENDED
  1529. .sp
  1530. If this bit is set, most white space characters in the pattern are totally
  1531. ignored except when escaped or inside a character class. However, white space
  1532. is not allowed within sequences such as (?> that introduce various
  1533. parenthesized groups, nor within numerical quantifiers such as {1,3}. Ignorable
  1534. white space is permitted between an item and a following quantifier and between
  1535. a quantifier and a following + that indicates possessiveness. PCRE2_EXTENDED is
  1536. equivalent to Perl's /x option, and it can be changed within a pattern by a
  1537. (?x) option setting.
  1538. .P
  1539. When PCRE2 is compiled without Unicode support, PCRE2_EXTENDED recognizes as
  1540. white space only those characters with code points less than 256 that are
  1541. flagged as white space in its low-character table. The table is normally
  1542. created by
  1543. .\" HREF
  1544. \fBpcre2_maketables()\fP,
  1545. .\"
  1546. which uses the \fBisspace()\fP function to identify space characters. In most
  1547. ASCII environments, the relevant characters are those with code points 0x0009
  1548. (tab), 0x000A (linefeed), 0x000B (vertical tab), 0x000C (formfeed), 0x000D
  1549. (carriage return), and 0x0020 (space).
  1550. .P
  1551. When PCRE2 is compiled with Unicode support, in addition to these characters,
  1552. five more Unicode "Pattern White Space" characters are recognized by
  1553. PCRE2_EXTENDED. These are U+0085 (next line), U+200E (left-to-right mark),
  1554. U+200F (right-to-left mark), U+2028 (line separator), and U+2029 (paragraph
  1555. separator). This set of characters is the same as recognized by Perl's /x
  1556. option. Note that the horizontal and vertical space characters that are matched
  1557. by the \eh and \ev escapes in patterns are a much bigger set.
  1558. .P
  1559. As well as ignoring most white space, PCRE2_EXTENDED also causes characters
  1560. between an unescaped # outside a character class and the next newline,
  1561. inclusive, to be ignored, which makes it possible to include comments inside
  1562. complicated patterns. Note that the end of this type of comment is a literal
  1563. newline sequence in the pattern; escape sequences that happen to represent a
  1564. newline do not count.
  1565. .P
  1566. Which characters are interpreted as newlines can be specified by a setting in
  1567. the compile context that is passed to \fBpcre2_compile()\fP or by a special
  1568. sequence at the start of the pattern, as described in the section entitled
  1569. .\" HTML <a href="pcre2pattern.html#newlines">
  1570. .\" </a>
  1571. "Newline conventions"
  1572. .\"
  1573. in the \fBpcre2pattern\fP documentation. A default is defined when PCRE2 is
  1574. built.
  1575. .sp
  1576. PCRE2_EXTENDED_MORE
  1577. .sp
  1578. This option has the effect of PCRE2_EXTENDED, but, in addition, unescaped space
  1579. and horizontal tab characters are ignored inside a character class. Note: only
  1580. these two characters are ignored, not the full set of pattern white space
  1581. characters that are ignored outside a character class. PCRE2_EXTENDED_MORE is
  1582. equivalent to Perl's /xx option, and it can be changed within a pattern by a
  1583. (?xx) option setting.
  1584. .sp
  1585. PCRE2_FIRSTLINE
  1586. .sp
  1587. If this option is set, the start of an unanchored pattern match must be before
  1588. or at the first newline in the subject string following the start of matching,
  1589. though the matched text may continue over the newline. If \fIstartoffset\fP is
  1590. non-zero, the limiting newline is not necessarily the first newline in the
  1591. subject. For example, if the subject string is "abc\enxyz" (where \en
  1592. represents a single-character newline) a pattern match for "yz" succeeds with
  1593. PCRE2_FIRSTLINE if \fIstartoffset\fP is greater than 3. See also
  1594. PCRE2_USE_OFFSET_LIMIT, which provides a more general limiting facility. If
  1595. PCRE2_FIRSTLINE is set with an offset limit, a match must occur in the first
  1596. line and also within the offset limit. In other words, whichever limit comes
  1597. first is used.
  1598. .sp
  1599. PCRE2_LITERAL
  1600. .sp
  1601. If this option is set, all meta-characters in the pattern are disabled, and it
  1602. is treated as a literal string. Matching literal strings with a regular
  1603. expression engine is not the most efficient way of doing it. If you are doing a
  1604. lot of literal matching and are worried about efficiency, you should consider
  1605. using other approaches. The only other main options that are allowed with
  1606. PCRE2_LITERAL are: PCRE2_ANCHORED, PCRE2_ENDANCHORED, PCRE2_AUTO_CALLOUT,
  1607. PCRE2_CASELESS, PCRE2_FIRSTLINE, PCRE2_MATCH_INVALID_UTF,
  1608. PCRE2_NO_START_OPTIMIZE, PCRE2_NO_UTF_CHECK, PCRE2_UTF, and
  1609. PCRE2_USE_OFFSET_LIMIT. The extra options PCRE2_EXTRA_MATCH_LINE and
  1610. PCRE2_EXTRA_MATCH_WORD are also supported. Any other options cause an error.
  1611. .sp
  1612. PCRE2_MATCH_INVALID_UTF
  1613. .sp
  1614. This option forces PCRE2_UTF (see below) and also enables support for matching
  1615. by \fBpcre2_match()\fP in subject strings that contain invalid UTF sequences.
  1616. This facility is not supported for DFA matching. For details, see the
  1617. .\" HREF
  1618. \fBpcre2unicode\fP
  1619. .\"
  1620. documentation.
  1621. .sp
  1622. PCRE2_MATCH_UNSET_BACKREF
  1623. .sp
  1624. If this option is set, a backreference to an unset capture group matches an
  1625. empty string (by default this causes the current matching alternative to fail).
  1626. A pattern such as (\e1)(a) succeeds when this option is set (assuming it can
  1627. find an "a" in the subject), whereas it fails by default, for Perl
  1628. compatibility. Setting this option makes PCRE2 behave more like ECMAscript (aka
  1629. JavaScript).
  1630. .sp
  1631. PCRE2_MULTILINE
  1632. .sp
  1633. By default, for the purposes of matching "start of line" and "end of line",
  1634. PCRE2 treats the subject string as consisting of a single line of characters,
  1635. even if it actually contains newlines. The "start of line" metacharacter (^)
  1636. matches only at the start of the string, and the "end of line" metacharacter
  1637. ($) matches only at the end of the string, or before a terminating newline
  1638. (except when PCRE2_DOLLAR_ENDONLY is set). Note, however, that unless
  1639. PCRE2_DOTALL is set, the "any character" metacharacter (.) does not match at a
  1640. newline. This behaviour (for ^, $, and dot) is the same as Perl.
  1641. .P
  1642. When PCRE2_MULTILINE it is set, the "start of line" and "end of line"
  1643. constructs match immediately following or immediately before internal newlines
  1644. in the subject string, respectively, as well as at the very start and end. This
  1645. is equivalent to Perl's /m option, and it can be changed within a pattern by a
  1646. (?m) option setting. Note that the "start of line" metacharacter does not match
  1647. after a newline at the end of the subject, for compatibility with Perl.
  1648. However, you can change this by setting the PCRE2_ALT_CIRCUMFLEX option. If
  1649. there are no newlines in a subject string, or no occurrences of ^ or $ in a
  1650. pattern, setting PCRE2_MULTILINE has no effect.
  1651. .sp
  1652. PCRE2_NEVER_BACKSLASH_C
  1653. .sp
  1654. This option locks out the use of \eC in the pattern that is being compiled.
  1655. This escape can cause unpredictable behaviour in UTF-8 or UTF-16 modes, because
  1656. it may leave the current matching point in the middle of a multi-code-unit
  1657. character. This option may be useful in applications that process patterns from
  1658. external sources. Note that there is also a build-time option that permanently
  1659. locks out the use of \eC.
  1660. .sp
  1661. PCRE2_NEVER_UCP
  1662. .sp
  1663. This option locks out the use of Unicode properties for handling \eB, \eb, \eD,
  1664. \ed, \eS, \es, \eW, \ew, and some of the POSIX character classes, as described
  1665. for the PCRE2_UCP option below. In particular, it prevents the creator of the
  1666. pattern from enabling this facility by starting the pattern with (*UCP). This
  1667. option may be useful in applications that process patterns from external
  1668. sources. The option combination PCRE_UCP and PCRE_NEVER_UCP causes an error.
  1669. .sp
  1670. PCRE2_NEVER_UTF
  1671. .sp
  1672. This option locks out interpretation of the pattern as UTF-8, UTF-16, or
  1673. UTF-32, depending on which library is in use. In particular, it prevents the
  1674. creator of the pattern from switching to UTF interpretation by starting the
  1675. pattern with (*UTF). This option may be useful in applications that process
  1676. patterns from external sources. The combination of PCRE2_UTF and
  1677. PCRE2_NEVER_UTF causes an error.
  1678. .sp
  1679. PCRE2_NO_AUTO_CAPTURE
  1680. .sp
  1681. If this option is set, it disables the use of numbered capturing parentheses in
  1682. the pattern. Any opening parenthesis that is not followed by ? behaves as if it
  1683. were followed by ?: but named parentheses can still be used for capturing (and
  1684. they acquire numbers in the usual way). This is the same as Perl's /n option.
  1685. Note that, when this option is set, references to capture groups
  1686. (backreferences or recursion/subroutine calls) may only refer to named groups,
  1687. though the reference can be by name or by number.
  1688. .sp
  1689. PCRE2_NO_AUTO_POSSESS
  1690. .sp
  1691. If this option is set, it disables "auto-possessification", which is an
  1692. optimization that, for example, turns a+b into a++b in order to avoid
  1693. backtracks into a+ that can never be successful. However, if callouts are in
  1694. use, auto-possessification means that some callouts are never taken. You can
  1695. set this option if you want the matching functions to do a full unoptimized
  1696. search and run all the callouts, but it is mainly provided for testing
  1697. purposes.
  1698. .sp
  1699. PCRE2_NO_DOTSTAR_ANCHOR
  1700. .sp
  1701. If this option is set, it disables an optimization that is applied when .* is
  1702. the first significant item in a top-level branch of a pattern, and all the
  1703. other branches also start with .* or with \eA or \eG or ^. The optimization is
  1704. automatically disabled for .* if it is inside an atomic group or a capture
  1705. group that is the subject of a backreference, or if the pattern contains
  1706. (*PRUNE) or (*SKIP). When the optimization is not disabled, such a pattern is
  1707. automatically anchored if PCRE2_DOTALL is set for all the .* items and
  1708. PCRE2_MULTILINE is not set for any ^ items. Otherwise, the fact that any match
  1709. must start either at the start of the subject or following a newline is
  1710. remembered. Like other optimizations, this can cause callouts to be skipped.
  1711. .sp
  1712. PCRE2_NO_START_OPTIMIZE
  1713. .sp
  1714. This is an option whose main effect is at matching time. It does not change
  1715. what \fBpcre2_compile()\fP generates, but it does affect the output of the JIT
  1716. compiler.
  1717. .P
  1718. There are a number of optimizations that may occur at the start of a match, in
  1719. order to speed up the process. For example, if it is known that an unanchored
  1720. match must start with a specific code unit value, the matching code searches
  1721. the subject for that value, and fails immediately if it cannot find it, without
  1722. actually running the main matching function. This means that a special item
  1723. such as (*COMMIT) at the start of a pattern is not considered until after a
  1724. suitable starting point for the match has been found. Also, when callouts or
  1725. (*MARK) items are in use, these "start-up" optimizations can cause them to be
  1726. skipped if the pattern is never actually used. The start-up optimizations are
  1727. in effect a pre-scan of the subject that takes place before the pattern is run.
  1728. .P
  1729. The PCRE2_NO_START_OPTIMIZE option disables the start-up optimizations,
  1730. possibly causing performance to suffer, but ensuring that in cases where the
  1731. result is "no match", the callouts do occur, and that items such as (*COMMIT)
  1732. and (*MARK) are considered at every possible starting position in the subject
  1733. string.
  1734. .P
  1735. Setting PCRE2_NO_START_OPTIMIZE may change the outcome of a matching operation.
  1736. Consider the pattern
  1737. .sp
  1738. (*COMMIT)ABC
  1739. .sp
  1740. When this is compiled, PCRE2 records the fact that a match must start with the
  1741. character "A". Suppose the subject string is "DEFABC". The start-up
  1742. optimization scans along the subject, finds "A" and runs the first match
  1743. attempt from there. The (*COMMIT) item means that the pattern must match the
  1744. current starting position, which in this case, it does. However, if the same
  1745. match is run with PCRE2_NO_START_OPTIMIZE set, the initial scan along the
  1746. subject string does not happen. The first match attempt is run starting from
  1747. "D" and when this fails, (*COMMIT) prevents any further matches being tried, so
  1748. the overall result is "no match".
  1749. .P
  1750. As another start-up optimization makes use of a minimum length for a matching
  1751. subject, which is recorded when possible. Consider the pattern
  1752. .sp
  1753. (*MARK:1)B(*MARK:2)(X|Y)
  1754. .sp
  1755. The minimum length for a match is two characters. If the subject is "XXBB", the
  1756. "starting character" optimization skips "XX", then tries to match "BB", which
  1757. is long enough. In the process, (*MARK:2) is encountered and remembered. When
  1758. the match attempt fails, the next "B" is found, but there is only one character
  1759. left, so there are no more attempts, and "no match" is returned with the "last
  1760. mark seen" set to "2". If NO_START_OPTIMIZE is set, however, matches are tried
  1761. at every possible starting position, including at the end of the subject, where
  1762. (*MARK:1) is encountered, but there is no "B", so the "last mark seen" that is
  1763. returned is "1". In this case, the optimizations do not affect the overall
  1764. match result, which is still "no match", but they do affect the auxiliary
  1765. information that is returned.
  1766. .sp
  1767. PCRE2_NO_UTF_CHECK
  1768. .sp
  1769. When PCRE2_UTF is set, the validity of the pattern as a UTF string is
  1770. automatically checked. There are discussions about the validity of
  1771. .\" HTML <a href="pcre2unicode.html#utf8strings">
  1772. .\" </a>
  1773. UTF-8 strings,
  1774. .\"
  1775. .\" HTML <a href="pcre2unicode.html#utf16strings">
  1776. .\" </a>
  1777. UTF-16 strings,
  1778. .\"
  1779. and
  1780. .\" HTML <a href="pcre2unicode.html#utf32strings">
  1781. .\" </a>
  1782. UTF-32 strings
  1783. .\"
  1784. in the
  1785. .\" HREF
  1786. \fBpcre2unicode\fP
  1787. .\"
  1788. document. If an invalid UTF sequence is found, \fBpcre2_compile()\fP returns a
  1789. negative error code.
  1790. .P
  1791. If you know that your pattern is a valid UTF string, and you want to skip this
  1792. check for performance reasons, you can set the PCRE2_NO_UTF_CHECK option. When
  1793. it is set, the effect of passing an invalid UTF string as a pattern is
  1794. undefined. It may cause your program to crash or loop.
  1795. .P
  1796. Note that this option can also be passed to \fBpcre2_match()\fP and
  1797. \fBpcre_dfa_match()\fP, to suppress UTF validity checking of the subject
  1798. string.
  1799. .P
  1800. Note also that setting PCRE2_NO_UTF_CHECK at compile time does not disable the
  1801. error that is given if an escape sequence for an invalid Unicode code point is
  1802. encountered in the pattern. In particular, the so-called "surrogate" code
  1803. points (0xd800 to 0xdfff) are invalid. If you want to allow escape sequences
  1804. such as \ex{d800} you can set the PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES extra
  1805. option, as described in the section entitled "Extra compile options"
  1806. .\" HTML <a href="#extracompileoptions">
  1807. .\" </a>
  1808. below.
  1809. .\"
  1810. However, this is possible only in UTF-8 and UTF-32 modes, because these values
  1811. are not representable in UTF-16.
  1812. .sp
  1813. PCRE2_UCP
  1814. .sp
  1815. This option has two effects. Firstly, it change the way PCRE2 processes \eB,
  1816. \eb, \eD, \ed, \eS, \es, \eW, \ew, and some of the POSIX character classes. By
  1817. default, only ASCII characters are recognized, but if PCRE2_UCP is set, Unicode
  1818. properties are used instead to classify characters. More details are given in
  1819. the section on
  1820. .\" HTML <a href="pcre2pattern.html#genericchartypes">
  1821. .\" </a>
  1822. generic character types
  1823. .\"
  1824. in the
  1825. .\" HREF
  1826. \fBpcre2pattern\fP
  1827. .\"
  1828. page. If you set PCRE2_UCP, matching one of the items it affects takes much
  1829. longer.
  1830. .P
  1831. The second effect of PCRE2_UCP is to force the use of Unicode properties for
  1832. upper/lower casing operations on characters with code points greater than 127,
  1833. even when PCRE2_UTF is not set. This makes it possible, for example, to process
  1834. strings in the 16-bit UCS-2 code. This option is available only if PCRE2 has
  1835. been compiled with Unicode support (which is the default).
  1836. .sp
  1837. PCRE2_UNGREEDY
  1838. .sp
  1839. This option inverts the "greediness" of the quantifiers so that they are not
  1840. greedy by default, but become greedy if followed by "?". It is not compatible
  1841. with Perl. It can also be set by a (?U) option setting within the pattern.
  1842. .sp
  1843. PCRE2_USE_OFFSET_LIMIT
  1844. .sp
  1845. This option must be set for \fBpcre2_compile()\fP if
  1846. \fBpcre2_set_offset_limit()\fP is going to be used to set a non-default offset
  1847. limit in a match context for matches that use this pattern. An error is
  1848. generated if an offset limit is set without this option. For more details, see
  1849. the description of \fBpcre2_set_offset_limit()\fP in the
  1850. .\" HTML <a href="#matchcontext">
  1851. .\" </a>
  1852. section
  1853. .\"
  1854. that describes match contexts. See also the PCRE2_FIRSTLINE
  1855. option above.
  1856. .sp
  1857. PCRE2_UTF
  1858. .sp
  1859. This option causes PCRE2 to regard both the pattern and the subject strings
  1860. that are subsequently processed as strings of UTF characters instead of
  1861. single-code-unit strings. It is available when PCRE2 is built to include
  1862. Unicode support (which is the default). If Unicode support is not available,
  1863. the use of this option provokes an error. Details of how PCRE2_UTF changes the
  1864. behaviour of PCRE2 are given in the
  1865. .\" HREF
  1866. \fBpcre2unicode\fP
  1867. .\"
  1868. page. In particular, note that it changes the way PCRE2_CASELESS handles
  1869. characters with code points greater than 127.
  1870. .
  1871. .
  1872. .\" HTML <a name="extracompileoptions"></a>
  1873. .SS "Extra compile options"
  1874. .rs
  1875. .sp
  1876. The option bits that can be set in a compile context by calling the
  1877. \fBpcre2_set_compile_extra_options()\fP function are as follows:
  1878. .sp
  1879. PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK
  1880. .sp
  1881. Since release 10.38 PCRE2 has forbidden the use of \eK within lookaround
  1882. assertions, following Perl's lead. This option is provided to re-enable the
  1883. previous behaviour (act in positive lookarounds, ignore in negative ones) in
  1884. case anybody is relying on it.
  1885. .sp
  1886. PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES
  1887. .sp
  1888. This option applies when compiling a pattern in UTF-8 or UTF-32 mode. It is
  1889. forbidden in UTF-16 mode, and ignored in non-UTF modes. Unicode "surrogate"
  1890. code points in the range 0xd800 to 0xdfff are used in pairs in UTF-16 to encode
  1891. code points with values in the range 0x10000 to 0x10ffff. The surrogates cannot
  1892. therefore be represented in UTF-16. They can be represented in UTF-8 and
  1893. UTF-32, but are defined as invalid code points, and cause errors if encountered
  1894. in a UTF-8 or UTF-32 string that is being checked for validity by PCRE2.
  1895. .P
  1896. These values also cause errors if encountered in escape sequences such as
  1897. \ex{d912} within a pattern. However, it seems that some applications, when
  1898. using PCRE2 to check for unwanted characters in UTF-8 strings, explicitly test
  1899. for the surrogates using escape sequences. The PCRE2_NO_UTF_CHECK option does
  1900. not disable the error that occurs, because it applies only to the testing of
  1901. input strings for UTF validity.
  1902. .P
  1903. If the extra option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is set, surrogate code
  1904. point values in UTF-8 and UTF-32 patterns no longer provoke errors and are
  1905. incorporated in the compiled pattern. However, they can only match subject
  1906. characters if the matching function is called with PCRE2_NO_UTF_CHECK set.
  1907. .sp
  1908. PCRE2_EXTRA_ALT_BSUX
  1909. .sp
  1910. The original option PCRE2_ALT_BSUX causes PCRE2 to process \eU, \eu, and \ex in
  1911. the way that ECMAscript (aka JavaScript) does. Additional functionality was
  1912. defined by ECMAscript 6; setting PCRE2_EXTRA_ALT_BSUX has the effect of
  1913. PCRE2_ALT_BSUX, but in addition it recognizes \eu{hhh..} as a hexadecimal
  1914. character code, where hhh.. is any number of hexadecimal digits.
  1915. .sp
  1916. PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL
  1917. .sp
  1918. This is a dangerous option. Use with care. By default, an unrecognized escape
  1919. such as \ej or a malformed one such as \ex{2z} causes a compile-time error when
  1920. detected by \fBpcre2_compile()\fP. Perl is somewhat inconsistent in handling
  1921. such items: for example, \ej is treated as a literal "j", and non-hexadecimal
  1922. digits in \ex{} are just ignored, though warnings are given in both cases if
  1923. Perl's warning switch is enabled. However, a malformed octal number after \eo{
  1924. always causes an error in Perl.
  1925. .P
  1926. If the PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL extra option is passed to
  1927. \fBpcre2_compile()\fP, all unrecognized or malformed escape sequences are
  1928. treated as single-character escapes. For example, \ej is a literal "j" and
  1929. \ex{2z} is treated as the literal string "x{2z}". Setting this option means
  1930. that typos in patterns may go undetected and have unexpected results. Also note
  1931. that a sequence such as [\eN{] is interpreted as a malformed attempt at
  1932. [\eN{...}] and so is treated as [N{] whereas [\eN] gives an error because an
  1933. unqualified \eN is a valid escape sequence but is not supported in a character
  1934. class. To reiterate: this is a dangerous option. Use with great care.
  1935. .sp
  1936. PCRE2_EXTRA_ESCAPED_CR_IS_LF
  1937. .sp
  1938. There are some legacy applications where the escape sequence \er in a pattern
  1939. is expected to match a newline. If this option is set, \er in a pattern is
  1940. converted to \en so that it matches a LF (linefeed) instead of a CR (carriage
  1941. return) character. The option does not affect a literal CR in the pattern, nor
  1942. does it affect CR specified as an explicit code point such as \ex{0D}.
  1943. .sp
  1944. PCRE2_EXTRA_MATCH_LINE
  1945. .sp
  1946. This option is provided for use by the \fB-x\fP option of \fBpcre2grep\fP. It
  1947. causes the pattern only to match complete lines. This is achieved by
  1948. automatically inserting the code for "^(?:" at the start of the compiled
  1949. pattern and ")$" at the end. Thus, when PCRE2_MULTILINE is set, the matched
  1950. line may be in the middle of the subject string. This option can be used with
  1951. PCRE2_LITERAL.
  1952. .sp
  1953. PCRE2_EXTRA_MATCH_WORD
  1954. .sp
  1955. This option is provided for use by the \fB-w\fP option of \fBpcre2grep\fP. It
  1956. causes the pattern only to match strings that have a word boundary at the start
  1957. and the end. This is achieved by automatically inserting the code for "\eb(?:"
  1958. at the start of the compiled pattern and ")\eb" at the end. The option may be
  1959. used with PCRE2_LITERAL. However, it is ignored if PCRE2_EXTRA_MATCH_LINE is
  1960. also set.
  1961. .
  1962. .
  1963. .\" HTML <a name="jitcompiling"></a>
  1964. .SH "JUST-IN-TIME (JIT) COMPILATION"
  1965. .rs
  1966. .sp
  1967. .nf
  1968. .B int pcre2_jit_compile(pcre2_code *\fIcode\fP, uint32_t \fIoptions\fP);
  1969. .sp
  1970. .B int pcre2_jit_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  1971. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  1972. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  1973. .B " pcre2_match_context *\fImcontext\fP);"
  1974. .sp
  1975. .B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP);
  1976. .sp
  1977. .B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
  1978. .B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
  1979. .sp
  1980. .B void pcre2_jit_stack_assign(pcre2_match_context *\fImcontext\fP,
  1981. .B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);"
  1982. .sp
  1983. .B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP);
  1984. .fi
  1985. .P
  1986. These functions provide support for JIT compilation, which, if the just-in-time
  1987. compiler is available, further processes a compiled pattern into machine code
  1988. that executes much faster than the \fBpcre2_match()\fP interpretive matching
  1989. function. Full details are given in the
  1990. .\" HREF
  1991. \fBpcre2jit\fP
  1992. .\"
  1993. documentation.
  1994. .P
  1995. JIT compilation is a heavyweight optimization. It can take some time for
  1996. patterns to be analyzed, and for one-off matches and simple patterns the
  1997. benefit of faster execution might be offset by a much slower compilation time.
  1998. Most (but not all) patterns can be optimized by the JIT compiler.
  1999. .
  2000. .
  2001. .\" HTML <a name="localesupport"></a>
  2002. .SH "LOCALE SUPPORT"
  2003. .rs
  2004. .sp
  2005. .nf
  2006. .B const uint8_t *pcre2_maketables(pcre2_general_context *\fIgcontext\fP);
  2007. .sp
  2008. .B void pcre2_maketables_free(pcre2_general_context *\fIgcontext\fP,
  2009. .B " const uint8_t *\fItables\fP);"
  2010. .fi
  2011. .P
  2012. PCRE2 handles caseless matching, and determines whether characters are letters,
  2013. digits, or whatever, by reference to a set of tables, indexed by character code
  2014. point. However, this applies only to characters whose code points are less than
  2015. 256. By default, higher-valued code points never match escapes such as \ew or
  2016. \ed.
  2017. .P
  2018. When PCRE2 is built with Unicode support (the default), the Unicode properties
  2019. of all characters can be tested with \ep and \eP, or, alternatively, the
  2020. PCRE2_UCP option can be set when a pattern is compiled; this causes \ew and
  2021. friends to use Unicode property support instead of the built-in tables.
  2022. PCRE2_UCP also causes upper/lower casing operations on characters with code
  2023. points greater than 127 to use Unicode properties. These effects apply even
  2024. when PCRE2_UTF is not set.
  2025. .P
  2026. The use of locales with Unicode is discouraged. If you are handling characters
  2027. with code points greater than 127, you should either use Unicode support, or
  2028. use locales, but not try to mix the two.
  2029. .P
  2030. PCRE2 contains a built-in set of character tables that are used by default.
  2031. These are sufficient for many applications. Normally, the internal tables
  2032. recognize only ASCII characters. However, when PCRE2 is built, it is possible
  2033. to cause the internal tables to be rebuilt in the default "C" locale of the
  2034. local system, which may cause them to be different.
  2035. .P
  2036. The built-in tables can be overridden by tables supplied by the application
  2037. that calls PCRE2. These may be created in a different locale from the default.
  2038. As more and more applications change to using Unicode, the need for this locale
  2039. support is expected to die away.
  2040. .P
  2041. External tables are built by calling the \fBpcre2_maketables()\fP function, in
  2042. the relevant locale. The only argument to this function is a general context,
  2043. which can be used to pass a custom memory allocator. If the argument is NULL,
  2044. the system \fBmalloc()\fP is used. The result can be passed to
  2045. \fBpcre2_compile()\fP as often as necessary, by creating a compile context and
  2046. calling \fBpcre2_set_character_tables()\fP to set the tables pointer therein.
  2047. .P
  2048. For example, to build and use tables that are appropriate for the French locale
  2049. (where accented characters with values greater than 127 are treated as
  2050. letters), the following code could be used:
  2051. .sp
  2052. setlocale(LC_CTYPE, "fr_FR");
  2053. tables = pcre2_maketables(NULL);
  2054. ccontext = pcre2_compile_context_create(NULL);
  2055. pcre2_set_character_tables(ccontext, tables);
  2056. re = pcre2_compile(..., ccontext);
  2057. .sp
  2058. The locale name "fr_FR" is used on Linux and other Unix-like systems; if you
  2059. are using Windows, the name for the French locale is "french".
  2060. .P
  2061. The pointer that is passed (via the compile context) to \fBpcre2_compile()\fP
  2062. is saved with the compiled pattern, and the same tables are used by the
  2063. matching functions. Thus, for any single pattern, compilation and matching both
  2064. happen in the same locale, but different patterns can be processed in different
  2065. locales.
  2066. .P
  2067. It is the caller's responsibility to ensure that the memory containing the
  2068. tables remains available while they are still in use. When they are no longer
  2069. needed, you can discard them using \fBpcre2_maketables_free()\fP, which should
  2070. pass as its first parameter the same global context that was used to create the
  2071. tables.
  2072. .
  2073. .
  2074. .SS "Saving locale tables"
  2075. .rs
  2076. .sp
  2077. The tables described above are just a sequence of binary bytes, which makes
  2078. them independent of hardware characteristics such as endianness or whether the
  2079. processor is 32-bit or 64-bit. A copy of the result of \fBpcre2_maketables()\fP
  2080. can therefore be saved in a file or elsewhere and re-used later, even in a
  2081. different program or on another computer. The size of the tables (number of
  2082. bytes) must be obtained by calling \fBpcre2_config()\fP with the
  2083. PCRE2_CONFIG_TABLES_LENGTH option because \fBpcre2_maketables()\fP does not
  2084. return this value. Note that the \fBpcre2_dftables\fP program, which is part of
  2085. the PCRE2 build system, can be used stand-alone to create a file that contains
  2086. a set of binary tables. See the
  2087. .\" HTML <a href="pcre2build.html#createtables">
  2088. .\" </a>
  2089. \fBpcre2build\fP
  2090. .\"
  2091. documentation for details.
  2092. .
  2093. .
  2094. .\" HTML <a name="infoaboutpattern"></a>
  2095. .SH "INFORMATION ABOUT A COMPILED PATTERN"
  2096. .rs
  2097. .sp
  2098. .nf
  2099. .B int pcre2_pattern_info(const pcre2 *\fIcode\fP, uint32_t \fIwhat\fP, void *\fIwhere\fP);
  2100. .fi
  2101. .P
  2102. The \fBpcre2_pattern_info()\fP function returns general information about a
  2103. compiled pattern. For information about callouts, see the
  2104. .\" HTML <a href="#infoaboutcallouts">
  2105. .\" </a>
  2106. next section.
  2107. .\"
  2108. The first argument for \fBpcre2_pattern_info()\fP is a pointer to the compiled
  2109. pattern. The second argument specifies which piece of information is required,
  2110. and the third argument is a pointer to a variable to receive the data. If the
  2111. third argument is NULL, the first argument is ignored, and the function returns
  2112. the size in bytes of the variable that is required for the information
  2113. requested. Otherwise, the yield of the function is zero for success, or one of
  2114. the following negative numbers:
  2115. .sp
  2116. PCRE2_ERROR_NULL the argument \fIcode\fP was NULL
  2117. PCRE2_ERROR_BADMAGIC the "magic number" was not found
  2118. PCRE2_ERROR_BADOPTION the value of \fIwhat\fP was invalid
  2119. PCRE2_ERROR_UNSET the requested field is not set
  2120. .sp
  2121. The "magic number" is placed at the start of each compiled pattern as a simple
  2122. check against passing an arbitrary memory pointer. Here is a typical call of
  2123. \fBpcre2_pattern_info()\fP, to obtain the length of the compiled pattern:
  2124. .sp
  2125. int rc;
  2126. size_t length;
  2127. rc = pcre2_pattern_info(
  2128. re, /* result of pcre2_compile() */
  2129. PCRE2_INFO_SIZE, /* what is required */
  2130. &length); /* where to put the data */
  2131. .sp
  2132. The possible values for the second argument are defined in \fBpcre2.h\fP, and
  2133. are as follows:
  2134. .sp
  2135. PCRE2_INFO_ALLOPTIONS
  2136. PCRE2_INFO_ARGOPTIONS
  2137. PCRE2_INFO_EXTRAOPTIONS
  2138. .sp
  2139. Return copies of the pattern's options. The third argument should point to a
  2140. \fBuint32_t\fP variable. PCRE2_INFO_ARGOPTIONS returns exactly the options that
  2141. were passed to \fBpcre2_compile()\fP, whereas PCRE2_INFO_ALLOPTIONS returns
  2142. the compile options as modified by any top-level (*XXX) option settings such as
  2143. (*UTF) at the start of the pattern itself. PCRE2_INFO_EXTRAOPTIONS returns the
  2144. extra options that were set in the compile context by calling the
  2145. pcre2_set_compile_extra_options() function.
  2146. .P
  2147. For example, if the pattern /(*UTF)abc/ is compiled with the PCRE2_EXTENDED
  2148. option, the result for PCRE2_INFO_ALLOPTIONS is PCRE2_EXTENDED and PCRE2_UTF.
  2149. Option settings such as (?i) that can change within a pattern do not affect the
  2150. result of PCRE2_INFO_ALLOPTIONS, even if they appear right at the start of the
  2151. pattern. (This was different in some earlier releases.)
  2152. .P
  2153. A pattern compiled without PCRE2_ANCHORED is automatically anchored by PCRE2 if
  2154. the first significant item in every top-level branch is one of the following:
  2155. .sp
  2156. ^ unless PCRE2_MULTILINE is set
  2157. \eA always
  2158. \eG always
  2159. .* sometimes - see below
  2160. .sp
  2161. When .* is the first significant item, anchoring is possible only when all the
  2162. following are true:
  2163. .sp
  2164. .* is not in an atomic group
  2165. .\" JOIN
  2166. .* is not in a capture group that is the subject
  2167. of a backreference
  2168. PCRE2_DOTALL is in force for .*
  2169. Neither (*PRUNE) nor (*SKIP) appears in the pattern
  2170. PCRE2_NO_DOTSTAR_ANCHOR is not set
  2171. .sp
  2172. For patterns that are auto-anchored, the PCRE2_ANCHORED bit is set in the
  2173. options returned for PCRE2_INFO_ALLOPTIONS.
  2174. .sp
  2175. PCRE2_INFO_BACKREFMAX
  2176. .sp
  2177. Return the number of the highest backreference in the pattern. The third
  2178. argument should point to a \fBuint32_t\fP variable. Named capture groups
  2179. acquire numbers as well as names, and these count towards the highest
  2180. backreference. Backreferences such as \e4 or \eg{12} match the captured
  2181. characters of the given group, but in addition, the check that a capture
  2182. group is set in a conditional group such as (?(3)a|b) is also a backreference.
  2183. Zero is returned if there are no backreferences.
  2184. .sp
  2185. PCRE2_INFO_BSR
  2186. .sp
  2187. The output is a uint32_t integer whose value indicates what character sequences
  2188. the \eR escape sequence matches. A value of PCRE2_BSR_UNICODE means that \eR
  2189. matches any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means
  2190. that \eR matches only CR, LF, or CRLF.
  2191. .sp
  2192. PCRE2_INFO_CAPTURECOUNT
  2193. .sp
  2194. Return the highest capture group number in the pattern. In patterns where (?|
  2195. is not used, this is also the total number of capture groups. The third
  2196. argument should point to a \fBuint32_t\fP variable.
  2197. .sp
  2198. PCRE2_INFO_DEPTHLIMIT
  2199. .sp
  2200. If the pattern set a backtracking depth limit by including an item of the form
  2201. (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The third argument
  2202. should point to a uint32_t integer. If no such value has been set, the call to
  2203. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2204. limit will only be used during matching if it is less than the limit set or
  2205. defaulted by the caller of the match function.
  2206. .sp
  2207. PCRE2_INFO_FIRSTBITMAP
  2208. .sp
  2209. In the absence of a single first code unit for a non-anchored pattern,
  2210. \fBpcre2_compile()\fP may construct a 256-bit table that defines a fixed set of
  2211. values for the first code unit in any match. For example, a pattern that starts
  2212. with [abc] results in a table with three bits set. When code unit values
  2213. greater than 255 are supported, the flag bit for 255 means "any code unit of
  2214. value 255 or above". If such a table was constructed, a pointer to it is
  2215. returned. Otherwise NULL is returned. The third argument should point to a
  2216. \fBconst uint8_t *\fP variable.
  2217. .sp
  2218. PCRE2_INFO_FIRSTCODETYPE
  2219. .sp
  2220. Return information about the first code unit of any matched string, for a
  2221. non-anchored pattern. The third argument should point to a \fBuint32_t\fP
  2222. variable. If there is a fixed first value, for example, the letter "c" from a
  2223. pattern such as (cat|cow|coyote), 1 is returned, and the value can be retrieved
  2224. using PCRE2_INFO_FIRSTCODEUNIT. If there is no fixed first value, but it is
  2225. known that a match can occur only at the start of the subject or following a
  2226. newline in the subject, 2 is returned. Otherwise, and for anchored patterns, 0
  2227. is returned.
  2228. .sp
  2229. PCRE2_INFO_FIRSTCODEUNIT
  2230. .sp
  2231. Return the value of the first code unit of any matched string for a pattern
  2232. where PCRE2_INFO_FIRSTCODETYPE returns 1; otherwise return 0. The third
  2233. argument should point to a \fBuint32_t\fP variable. In the 8-bit library, the
  2234. value is always less than 256. In the 16-bit library the value can be up to
  2235. 0xffff. In the 32-bit library in UTF-32 mode the value can be up to 0x10ffff,
  2236. and up to 0xffffffff when not using UTF-32 mode.
  2237. .sp
  2238. PCRE2_INFO_FRAMESIZE
  2239. .sp
  2240. Return the size (in bytes) of the data frames that are used to remember
  2241. backtracking positions when the pattern is processed by \fBpcre2_match()\fP
  2242. without the use of JIT. The third argument should point to a \fBsize_t\fP
  2243. variable. The frame size depends on the number of capturing parentheses in the
  2244. pattern. Each additional capture group adds two PCRE2_SIZE variables.
  2245. .sp
  2246. PCRE2_INFO_HASBACKSLASHC
  2247. .sp
  2248. Return 1 if the pattern contains any instances of \eC, otherwise 0. The third
  2249. argument should point to a \fBuint32_t\fP variable.
  2250. .sp
  2251. PCRE2_INFO_HASCRORLF
  2252. .sp
  2253. Return 1 if the pattern contains any explicit matches for CR or LF characters,
  2254. otherwise 0. The third argument should point to a \fBuint32_t\fP variable. An
  2255. explicit match is either a literal CR or LF character, or \er or \en or one of
  2256. the equivalent hexadecimal or octal escape sequences.
  2257. .sp
  2258. PCRE2_INFO_HEAPLIMIT
  2259. .sp
  2260. If the pattern set a heap memory limit by including an item of the form
  2261. (*LIMIT_HEAP=nnnn) at the start, the value is returned. The third argument
  2262. should point to a uint32_t integer. If no such value has been set, the call to
  2263. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2264. limit will only be used during matching if it is less than the limit set or
  2265. defaulted by the caller of the match function.
  2266. .sp
  2267. PCRE2_INFO_JCHANGED
  2268. .sp
  2269. Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise
  2270. 0. The third argument should point to a \fBuint32_t\fP variable. (?J) and
  2271. (?-J) set and unset the local PCRE2_DUPNAMES option, respectively.
  2272. .sp
  2273. PCRE2_INFO_JITSIZE
  2274. .sp
  2275. If the compiled pattern was successfully processed by
  2276. \fBpcre2_jit_compile()\fP, return the size of the JIT compiled code, otherwise
  2277. return zero. The third argument should point to a \fBsize_t\fP variable.
  2278. .sp
  2279. PCRE2_INFO_LASTCODETYPE
  2280. .sp
  2281. Returns 1 if there is a rightmost literal code unit that must exist in any
  2282. matched string, other than at its start. The third argument should point to a
  2283. \fBuint32_t\fP variable. If there is no such value, 0 is returned. When 1 is
  2284. returned, the code unit value itself can be retrieved using
  2285. PCRE2_INFO_LASTCODEUNIT. For anchored patterns, a last literal value is
  2286. recorded only if it follows something of variable length. For example, for the
  2287. pattern /^a\ed+z\ed+/ the returned value is 1 (with "z" returned from
  2288. PCRE2_INFO_LASTCODEUNIT), but for /^a\edz\ed/ the returned value is 0.
  2289. .sp
  2290. PCRE2_INFO_LASTCODEUNIT
  2291. .sp
  2292. Return the value of the rightmost literal code unit that must exist in any
  2293. matched string, other than at its start, for a pattern where
  2294. PCRE2_INFO_LASTCODETYPE returns 1. Otherwise, return 0. The third argument
  2295. should point to a \fBuint32_t\fP variable.
  2296. .sp
  2297. PCRE2_INFO_MATCHEMPTY
  2298. .sp
  2299. Return 1 if the pattern might match an empty string, otherwise 0. The third
  2300. argument should point to a \fBuint32_t\fP variable. When a pattern contains
  2301. recursive subroutine calls it is not always possible to determine whether or
  2302. not it can match an empty string. PCRE2 takes a cautious approach and returns 1
  2303. in such cases.
  2304. .sp
  2305. PCRE2_INFO_MATCHLIMIT
  2306. .sp
  2307. If the pattern set a match limit by including an item of the form
  2308. (*LIMIT_MATCH=nnnn) at the start, the value is returned. The third argument
  2309. should point to a uint32_t integer. If no such value has been set, the call to
  2310. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2311. limit will only be used during matching if it is less than the limit set or
  2312. defaulted by the caller of the match function.
  2313. .sp
  2314. PCRE2_INFO_MAXLOOKBEHIND
  2315. .sp
  2316. A lookbehind assertion moves back a certain number of characters (not code
  2317. units) when it starts to process each of its branches. This request returns the
  2318. largest of these backward moves. The third argument should point to a uint32_t
  2319. integer. The simple assertions \eb and \eB require a one-character lookbehind
  2320. and cause PCRE2_INFO_MAXLOOKBEHIND to return 1 in the absence of anything
  2321. longer. \eA also registers a one-character lookbehind, though it does not
  2322. actually inspect the previous character.
  2323. .P
  2324. Note that this information is useful for multi-segment matching only
  2325. if the pattern contains no nested lookbehinds. For example, the pattern
  2326. (?<=a(?<=ba)c) returns a maximum lookbehind of 2, but when it is processed, the
  2327. first lookbehind moves back by two characters, matches one character, then the
  2328. nested lookbehind also moves back by two characters. This puts the matching
  2329. point three characters earlier than it was at the start.
  2330. PCRE2_INFO_MAXLOOKBEHIND is really only useful as a debugging tool. See the
  2331. .\" HREF
  2332. \fBpcre2partial\fP
  2333. .\"
  2334. documentation for a discussion of multi-segment matching.
  2335. .sp
  2336. PCRE2_INFO_MINLENGTH
  2337. .sp
  2338. If a minimum length for matching subject strings was computed, its value is
  2339. returned. Otherwise the returned value is 0. This value is not computed when
  2340. PCRE2_NO_START_OPTIMIZE is set. The value is a number of characters, which in
  2341. UTF mode may be different from the number of code units. The third argument
  2342. should point to a \fBuint32_t\fP variable. The value is a lower bound to the
  2343. length of any matching string. There may not be any strings of that length that
  2344. do actually match, but every string that does match is at least that long.
  2345. .sp
  2346. PCRE2_INFO_NAMECOUNT
  2347. PCRE2_INFO_NAMEENTRYSIZE
  2348. PCRE2_INFO_NAMETABLE
  2349. .sp
  2350. PCRE2 supports the use of named as well as numbered capturing parentheses. The
  2351. names are just an additional way of identifying the parentheses, which still
  2352. acquire numbers. Several convenience functions such as
  2353. \fBpcre2_substring_get_byname()\fP are provided for extracting captured
  2354. substrings by name. It is also possible to extract the data directly, by first
  2355. converting the name to a number in order to access the correct pointers in the
  2356. output vector (described with \fBpcre2_match()\fP below). To do the conversion,
  2357. you need to use the name-to-number map, which is described by these three
  2358. values.
  2359. .P
  2360. The map consists of a number of fixed-size entries. PCRE2_INFO_NAMECOUNT gives
  2361. the number of entries, and PCRE2_INFO_NAMEENTRYSIZE gives the size of each
  2362. entry in code units; both of these return a \fBuint32_t\fP value. The entry
  2363. size depends on the length of the longest name.
  2364. .P
  2365. PCRE2_INFO_NAMETABLE returns a pointer to the first entry of the table. This is
  2366. a PCRE2_SPTR pointer to a block of code units. In the 8-bit library, the first
  2367. two bytes of each entry are the number of the capturing parenthesis, most
  2368. significant byte first. In the 16-bit library, the pointer points to 16-bit
  2369. code units, the first of which contains the parenthesis number. In the 32-bit
  2370. library, the pointer points to 32-bit code units, the first of which contains
  2371. the parenthesis number. The rest of the entry is the corresponding name, zero
  2372. terminated.
  2373. .P
  2374. The names are in alphabetical order. If (?| is used to create multiple capture
  2375. groups with the same number, as described in the
  2376. .\" HTML <a href="pcre2pattern.html#dupgroupnumber">
  2377. .\" </a>
  2378. section on duplicate group numbers
  2379. .\"
  2380. in the
  2381. .\" HREF
  2382. \fBpcre2pattern\fP
  2383. .\"
  2384. page, the groups may be given the same name, but there is only one entry in the
  2385. table. Different names for groups of the same number are not permitted.
  2386. .P
  2387. Duplicate names for capture groups with different numbers are permitted, but
  2388. only if PCRE2_DUPNAMES is set. They appear in the table in the order in which
  2389. they were found in the pattern. In the absence of (?| this is the order of
  2390. increasing number; when (?| is used this is not necessarily the case because
  2391. later capture groups may have lower numbers.
  2392. .P
  2393. As a simple example of the name/number table, consider the following pattern
  2394. after compilation by the 8-bit library (assume PCRE2_EXTENDED is set, so white
  2395. space - including newlines - is ignored):
  2396. .sp
  2397. .\" JOIN
  2398. (?<date> (?<year>(\ed\ed)?\ed\ed) -
  2399. (?<month>\ed\ed) - (?<day>\ed\ed) )
  2400. .sp
  2401. There are four named capture groups, so the table has four entries, and each
  2402. entry in the table is eight bytes long. The table is as follows, with
  2403. non-printing bytes shows in hexadecimal, and undefined bytes shown as ??:
  2404. .sp
  2405. 00 01 d a t e 00 ??
  2406. 00 05 d a y 00 ?? ??
  2407. 00 04 m o n t h 00
  2408. 00 02 y e a r 00 ??
  2409. .sp
  2410. When writing code to extract data from named capture groups using the
  2411. name-to-number map, remember that the length of the entries is likely to be
  2412. different for each compiled pattern.
  2413. .sp
  2414. PCRE2_INFO_NEWLINE
  2415. .sp
  2416. The output is one of the following \fBuint32_t\fP values:
  2417. .sp
  2418. PCRE2_NEWLINE_CR Carriage return (CR)
  2419. PCRE2_NEWLINE_LF Linefeed (LF)
  2420. PCRE2_NEWLINE_CRLF Carriage return, linefeed (CRLF)
  2421. PCRE2_NEWLINE_ANY Any Unicode line ending
  2422. PCRE2_NEWLINE_ANYCRLF Any of CR, LF, or CRLF
  2423. PCRE2_NEWLINE_NUL The NUL character (binary zero)
  2424. .sp
  2425. This identifies the character sequence that will be recognized as meaning
  2426. "newline" while matching.
  2427. .sp
  2428. PCRE2_INFO_SIZE
  2429. .sp
  2430. Return the size of the compiled pattern in bytes (for all three libraries). The
  2431. third argument should point to a \fBsize_t\fP variable. This value includes the
  2432. size of the general data block that precedes the code units of the compiled
  2433. pattern itself. The value that is used when \fBpcre2_compile()\fP is getting
  2434. memory in which to place the compiled pattern may be slightly larger than the
  2435. value returned by this option, because there are cases where the code that
  2436. calculates the size has to over-estimate. Processing a pattern with the JIT
  2437. compiler does not alter the value returned by this option.
  2438. .
  2439. .
  2440. .\" HTML <a name="infoaboutcallouts"></a>
  2441. .SH "INFORMATION ABOUT A PATTERN'S CALLOUTS"
  2442. .rs
  2443. .sp
  2444. .nf
  2445. .B int pcre2_callout_enumerate(const pcre2_code *\fIcode\fP,
  2446. .B " int (*\fIcallback\fP)(pcre2_callout_enumerate_block *, void *),"
  2447. .B " void *\fIuser_data\fP);"
  2448. .fi
  2449. .sp
  2450. A script language that supports the use of string arguments in callouts might
  2451. like to scan all the callouts in a pattern before running the match. This can
  2452. be done by calling \fBpcre2_callout_enumerate()\fP. The first argument is a
  2453. pointer to a compiled pattern, the second points to a callback function, and
  2454. the third is arbitrary user data. The callback function is called for every
  2455. callout in the pattern in the order in which they appear. Its first argument is
  2456. a pointer to a callout enumeration block, and its second argument is the
  2457. \fIuser_data\fP value that was passed to \fBpcre2_callout_enumerate()\fP. The
  2458. contents of the callout enumeration block are described in the
  2459. .\" HREF
  2460. \fBpcre2callout\fP
  2461. .\"
  2462. documentation, which also gives further details about callouts.
  2463. .
  2464. .
  2465. .SH "SERIALIZATION AND PRECOMPILING"
  2466. .rs
  2467. .sp
  2468. It is possible to save compiled patterns on disc or elsewhere, and reload them
  2469. later, subject to a number of restrictions. The host on which the patterns are
  2470. reloaded must be running the same version of PCRE2, with the same code unit
  2471. width, and must also have the same endianness, pointer width, and PCRE2_SIZE
  2472. type. Before compiled patterns can be saved, they must be converted to a
  2473. "serialized" form, which in the case of PCRE2 is really just a bytecode dump.
  2474. The functions whose names begin with \fBpcre2_serialize_\fP are used for
  2475. converting to and from the serialized form. They are described in the
  2476. .\" HREF
  2477. \fBpcre2serialize\fP
  2478. .\"
  2479. documentation. Note that PCRE2 serialization does not convert compiled patterns
  2480. to an abstract format like Java or .NET serialization.
  2481. .
  2482. .
  2483. .\" HTML <a name="matchdatablock"></a>
  2484. .SH "THE MATCH DATA BLOCK"
  2485. .rs
  2486. .sp
  2487. .nf
  2488. .B pcre2_match_data *pcre2_match_data_create(uint32_t \fIovecsize\fP,
  2489. .B " pcre2_general_context *\fIgcontext\fP);"
  2490. .sp
  2491. .B pcre2_match_data *pcre2_match_data_create_from_pattern(
  2492. .B " const pcre2_code *\fIcode\fP, pcre2_general_context *\fIgcontext\fP);"
  2493. .sp
  2494. .B void pcre2_match_data_free(pcre2_match_data *\fImatch_data\fP);
  2495. .fi
  2496. .P
  2497. Information about a successful or unsuccessful match is placed in a match
  2498. data block, which is an opaque structure that is accessed by function calls. In
  2499. particular, the match data block contains a vector of offsets into the subject
  2500. string that define the matched parts of the subject. This is known as the
  2501. \fIovector\fP.
  2502. .P
  2503. Before calling \fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or
  2504. \fBpcre2_jit_match()\fP you must create a match data block by calling one of
  2505. the creation functions above. For \fBpcre2_match_data_create()\fP, the first
  2506. argument is the number of pairs of offsets in the \fIovector\fP.
  2507. .P
  2508. When using \fBpcre2_match()\fP, one pair of offsets is required to identify the
  2509. string that matched the whole pattern, with an additional pair for each
  2510. captured substring. For example, a value of 4 creates enough space to record
  2511. the matched portion of the subject plus three captured substrings.
  2512. .P
  2513. When using \fBpcre2_dfa_match()\fP there may be multiple matched substrings of
  2514. different lengths at the same point in the subject. The ovector should be made
  2515. large enough to hold as many as are expected.
  2516. .P
  2517. A minimum of at least 1 pair is imposed by \fBpcre2_match_data_create()\fP, so
  2518. it is always possible to return the overall matched string in the case of
  2519. \fBpcre2_match()\fP or the longest match in the case of
  2520. \fBpcre2_dfa_match()\fP.
  2521. .P
  2522. The second argument of \fBpcre2_match_data_create()\fP is a pointer to a
  2523. general context, which can specify custom memory management for obtaining the
  2524. memory for the match data block. If you are not using custom memory management,
  2525. pass NULL, which causes \fBmalloc()\fP to be used.
  2526. .P
  2527. For \fBpcre2_match_data_create_from_pattern()\fP, the first argument is a
  2528. pointer to a compiled pattern. The ovector is created to be exactly the right
  2529. size to hold all the substrings a pattern might capture when matched using
  2530. \fBpcre2_match()\fP. You should not use this call when matching with
  2531. \fBpcre2_dfa_match()\fP. The second argument is again a pointer to a general
  2532. context, but in this case if NULL is passed, the memory is obtained using the
  2533. same allocator that was used for the compiled pattern (custom or default).
  2534. .P
  2535. A match data block can be used many times, with the same or different compiled
  2536. patterns. You can extract information from a match data block after a match
  2537. operation has finished, using functions that are described in the sections on
  2538. .\" HTML <a href="#matchedstrings">
  2539. .\" </a>
  2540. matched strings
  2541. .\"
  2542. and
  2543. .\" HTML <a href="#matchotherdata">
  2544. .\" </a>
  2545. other match data
  2546. .\"
  2547. below.
  2548. .P
  2549. When a call of \fBpcre2_match()\fP fails, valid data is available in the match
  2550. block only when the error is PCRE2_ERROR_NOMATCH, PCRE2_ERROR_PARTIAL, or one
  2551. of the error codes for an invalid UTF string. Exactly what is available depends
  2552. on the error, and is detailed below.
  2553. .P
  2554. When one of the matching functions is called, pointers to the compiled pattern
  2555. and the subject string are set in the match data block so that they can be
  2556. referenced by the extraction functions after a successful match. After running
  2557. a match, you must not free a compiled pattern or a subject string until after
  2558. all operations on the match data block (for that match) have taken place,
  2559. unless, in the case of the subject string, you have used the
  2560. PCRE2_COPY_MATCHED_SUBJECT option, which is described in the section entitled
  2561. "Option bits for \fBpcre2_match()\fP"
  2562. .\" HTML <a href="#matchoptions>">
  2563. .\" </a>
  2564. below.
  2565. .\"
  2566. .P
  2567. When a match data block itself is no longer needed, it should be freed by
  2568. calling \fBpcre2_match_data_free()\fP. If this function is called with a NULL
  2569. argument, it returns immediately, without doing anything.
  2570. .
  2571. .
  2572. .SH "MATCHING A PATTERN: THE TRADITIONAL FUNCTION"
  2573. .rs
  2574. .sp
  2575. .nf
  2576. .B int pcre2_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  2577. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  2578. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  2579. .B " pcre2_match_context *\fImcontext\fP);"
  2580. .fi
  2581. .P
  2582. The function \fBpcre2_match()\fP is called to match a subject string against a
  2583. compiled pattern, which is passed in the \fIcode\fP argument. You can call
  2584. \fBpcre2_match()\fP with the same \fIcode\fP argument as many times as you
  2585. like, in order to find multiple matches in the subject string or to match
  2586. different subject strings with the same pattern.
  2587. .P
  2588. This function is the main matching facility of the library, and it operates in
  2589. a Perl-like manner. For specialist use there is also an alternative matching
  2590. function, which is described
  2591. .\" HTML <a href="#dfamatch">
  2592. .\" </a>
  2593. below
  2594. .\"
  2595. in the section about the \fBpcre2_dfa_match()\fP function.
  2596. .P
  2597. Here is an example of a simple call to \fBpcre2_match()\fP:
  2598. .sp
  2599. pcre2_match_data *md = pcre2_match_data_create(4, NULL);
  2600. int rc = pcre2_match(
  2601. re, /* result of pcre2_compile() */
  2602. "some string", /* the subject string */
  2603. 11, /* the length of the subject string */
  2604. 0, /* start at offset 0 in the subject */
  2605. 0, /* default options */
  2606. md, /* the match data block */
  2607. NULL); /* a match context; NULL means use defaults */
  2608. .sp
  2609. If the subject string is zero-terminated, the length can be given as
  2610. PCRE2_ZERO_TERMINATED. A match context must be provided if certain less common
  2611. matching parameters are to be changed. For details, see the section on
  2612. .\" HTML <a href="#matchcontext">
  2613. .\" </a>
  2614. the match context
  2615. .\"
  2616. above.
  2617. .
  2618. .
  2619. .SS "The string to be matched by \fBpcre2_match()\fP"
  2620. .rs
  2621. .sp
  2622. The subject string is passed to \fBpcre2_match()\fP as a pointer in
  2623. \fIsubject\fP, a length in \fIlength\fP, and a starting offset in
  2624. \fIstartoffset\fP. The length and offset are in code units, not characters.
  2625. That is, they are in bytes for the 8-bit library, 16-bit code units for the
  2626. 16-bit library, and 32-bit code units for the 32-bit library, whether or not
  2627. UTF processing is enabled.
  2628. .P
  2629. If \fIstartoffset\fP is greater than the length of the subject,
  2630. \fBpcre2_match()\fP returns PCRE2_ERROR_BADOFFSET. When the starting offset is
  2631. zero, the search for a match starts at the beginning of the subject, and this
  2632. is by far the most common case. In UTF-8 or UTF-16 mode, the starting offset
  2633. must point to the start of a character, or to the end of the subject (in UTF-32
  2634. mode, one code unit equals one character, so all offsets are valid). Like the
  2635. pattern string, the subject may contain binary zeros.
  2636. .P
  2637. A non-zero starting offset is useful when searching for another match in the
  2638. same subject by calling \fBpcre2_match()\fP again after a previous success.
  2639. Setting \fIstartoffset\fP differs from passing over a shortened string and
  2640. setting PCRE2_NOTBOL in the case of a pattern that begins with any kind of
  2641. lookbehind. For example, consider the pattern
  2642. .sp
  2643. \eBiss\eB
  2644. .sp
  2645. which finds occurrences of "iss" in the middle of words. (\eB matches only if
  2646. the current position in the subject is not a word boundary.) When applied to
  2647. the string "Mississippi" the first call to \fBpcre2_match()\fP finds the first
  2648. occurrence. If \fBpcre2_match()\fP is called again with just the remainder of
  2649. the subject, namely "issippi", it does not match, because \eB is always false
  2650. at the start of the subject, which is deemed to be a word boundary. However, if
  2651. \fBpcre2_match()\fP is passed the entire string again, but with
  2652. \fIstartoffset\fP set to 4, it finds the second occurrence of "iss" because it
  2653. is able to look behind the starting point to discover that it is preceded by a
  2654. letter.
  2655. .P
  2656. Finding all the matches in a subject is tricky when the pattern can match an
  2657. empty string. It is possible to emulate Perl's /g behaviour by first trying the
  2658. match again at the same offset, with the PCRE2_NOTEMPTY_ATSTART and
  2659. PCRE2_ANCHORED options, and then if that fails, advancing the starting offset
  2660. and trying an ordinary match again. There is some code that demonstrates how to
  2661. do this in the
  2662. .\" HREF
  2663. \fBpcre2demo\fP
  2664. .\"
  2665. sample program. In the most general case, you have to check to see if the
  2666. newline convention recognizes CRLF as a newline, and if so, and the current
  2667. character is CR followed by LF, advance the starting offset by two characters
  2668. instead of one.
  2669. .P
  2670. If a non-zero starting offset is passed when the pattern is anchored, a single
  2671. attempt to match at the given offset is made. This can only succeed if the
  2672. pattern does not require the match to be at the start of the subject. In other
  2673. words, the anchoring must be the result of setting the PCRE2_ANCHORED option or
  2674. the use of .* with PCRE2_DOTALL, not by starting the pattern with ^ or \eA.
  2675. .
  2676. .
  2677. .\" HTML <a name="matchoptions"></a>
  2678. .SS "Option bits for \fBpcre2_match()\fP"
  2679. .rs
  2680. .sp
  2681. The unused bits of the \fIoptions\fP argument for \fBpcre2_match()\fP must be
  2682. zero. The only bits that may be set are PCRE2_ANCHORED,
  2683. PCRE2_COPY_MATCHED_SUBJECT, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL,
  2684. PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_JIT, PCRE2_NO_UTF_CHECK,
  2685. PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. Their action is described below.
  2686. .P
  2687. Setting PCRE2_ANCHORED or PCRE2_ENDANCHORED at match time is not supported by
  2688. the just-in-time (JIT) compiler. If it is set, JIT matching is disabled and the
  2689. interpretive code in \fBpcre2_match()\fP is run. Apart from PCRE2_NO_JIT
  2690. (obviously), the remaining options are supported for JIT matching.
  2691. .sp
  2692. PCRE2_ANCHORED
  2693. .sp
  2694. The PCRE2_ANCHORED option limits \fBpcre2_match()\fP to matching at the first
  2695. matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out
  2696. to be anchored by virtue of its contents, it cannot be made unachored at
  2697. matching time. Note that setting the option at match time disables JIT
  2698. matching.
  2699. .sp
  2700. PCRE2_COPY_MATCHED_SUBJECT
  2701. .sp
  2702. By default, a pointer to the subject is remembered in the match data block so
  2703. that, after a successful match, it can be referenced by the substring
  2704. extraction functions. This means that the subject's memory must not be freed
  2705. until all such operations are complete. For some applications where the
  2706. lifetime of the subject string is not guaranteed, it may be necessary to make a
  2707. copy of the subject string, but it is wasteful to do this unless the match is
  2708. successful. After a successful match, if PCRE2_COPY_MATCHED_SUBJECT is set, the
  2709. subject is copied and the new pointer is remembered in the match data block
  2710. instead of the original subject pointer. The memory allocator that was used for
  2711. the match block itself is used. The copy is automatically freed when
  2712. \fBpcre2_match_data_free()\fP is called to free the match data block. It is also
  2713. automatically freed if the match data block is re-used for another match
  2714. operation.
  2715. .sp
  2716. PCRE2_ENDANCHORED
  2717. .sp
  2718. If the PCRE2_ENDANCHORED option is set, any string that \fBpcre2_match()\fP
  2719. matches must be right at the end of the subject string. Note that setting the
  2720. option at match time disables JIT matching.
  2721. .sp
  2722. PCRE2_NOTBOL
  2723. .sp
  2724. This option specifies that first character of the subject string is not the
  2725. beginning of a line, so the circumflex metacharacter should not match before
  2726. it. Setting this without having set PCRE2_MULTILINE at compile time causes
  2727. circumflex never to match. This option affects only the behaviour of the
  2728. circumflex metacharacter. It does not affect \eA.
  2729. .sp
  2730. PCRE2_NOTEOL
  2731. .sp
  2732. This option specifies that the end of the subject string is not the end of a
  2733. line, so the dollar metacharacter should not match it nor (except in multiline
  2734. mode) a newline immediately before it. Setting this without having set
  2735. PCRE2_MULTILINE at compile time causes dollar never to match. This option
  2736. affects only the behaviour of the dollar metacharacter. It does not affect \eZ
  2737. or \ez.
  2738. .sp
  2739. PCRE2_NOTEMPTY
  2740. .sp
  2741. An empty string is not considered to be a valid match if this option is set. If
  2742. there are alternatives in the pattern, they are tried. If all the alternatives
  2743. match the empty string, the entire match fails. For example, if the pattern
  2744. .sp
  2745. a?b?
  2746. .sp
  2747. is applied to a string not beginning with "a" or "b", it matches an empty
  2748. string at the start of the subject. With PCRE2_NOTEMPTY set, this match is not
  2749. valid, so \fBpcre2_match()\fP searches further into the string for occurrences
  2750. of "a" or "b".
  2751. .sp
  2752. PCRE2_NOTEMPTY_ATSTART
  2753. .sp
  2754. This is like PCRE2_NOTEMPTY, except that it locks out an empty string match
  2755. only at the first matching position, that is, at the start of the subject plus
  2756. the starting offset. An empty string match later in the subject is permitted.
  2757. If the pattern is anchored, such a match can occur only if the pattern contains
  2758. \eK.
  2759. .sp
  2760. PCRE2_NO_JIT
  2761. .sp
  2762. By default, if a pattern has been successfully processed by
  2763. \fBpcre2_jit_compile()\fP, JIT is automatically used when \fBpcre2_match()\fP
  2764. is called with options that JIT supports. Setting PCRE2_NO_JIT disables the use
  2765. of JIT; it forces matching to be done by the interpreter.
  2766. .sp
  2767. PCRE2_NO_UTF_CHECK
  2768. .sp
  2769. When PCRE2_UTF is set at compile time, the validity of the subject as a UTF
  2770. string is checked unless PCRE2_NO_UTF_CHECK is passed to \fBpcre2_match()\fP or
  2771. PCRE2_MATCH_INVALID_UTF was passed to \fBpcre2_compile()\fP. The latter special
  2772. case is discussed in detail in the
  2773. .\" HREF
  2774. \fBpcre2unicode\fP
  2775. .\"
  2776. documentation.
  2777. .P
  2778. In the default case, if a non-zero starting offset is given, the check is
  2779. applied only to that part of the subject that could be inspected during
  2780. matching, and there is a check that the starting offset points to the first
  2781. code unit of a character or to the end of the subject. If there are no
  2782. lookbehind assertions in the pattern, the check starts at the starting offset.
  2783. Otherwise, it starts at the length of the longest lookbehind before the
  2784. starting offset, or at the start of the subject if there are not that many
  2785. characters before the starting offset. Note that the sequences \eb and \eB are
  2786. one-character lookbehinds.
  2787. .P
  2788. The check is carried out before any other processing takes place, and a
  2789. negative error code is returned if the check fails. There are several UTF error
  2790. codes for each code unit width, corresponding to different problems with the
  2791. code unit sequence. There are discussions about the validity of
  2792. .\" HTML <a href="pcre2unicode.html#utf8strings">
  2793. .\" </a>
  2794. UTF-8 strings,
  2795. .\"
  2796. .\" HTML <a href="pcre2unicode.html#utf16strings">
  2797. .\" </a>
  2798. UTF-16 strings,
  2799. .\"
  2800. and
  2801. .\" HTML <a href="pcre2unicode.html#utf32strings">
  2802. .\" </a>
  2803. UTF-32 strings
  2804. .\"
  2805. in the
  2806. .\" HREF
  2807. \fBpcre2unicode\fP
  2808. .\"
  2809. documentation.
  2810. .P
  2811. If you know that your subject is valid, and you want to skip this check for
  2812. performance reasons, you can set the PCRE2_NO_UTF_CHECK option when calling
  2813. \fBpcre2_match()\fP. You might want to do this for the second and subsequent
  2814. calls to \fBpcre2_match()\fP if you are making repeated calls to find multiple
  2815. matches in the same subject string.
  2816. .P
  2817. \fBWarning:\fP Unless PCRE2_MATCH_INVALID_UTF was set at compile time, when
  2818. PCRE2_NO_UTF_CHECK is set at match time the effect of passing an invalid
  2819. string as a subject, or an invalid value of \fIstartoffset\fP, is undefined.
  2820. Your program may crash or loop indefinitely or give wrong results.
  2821. .sp
  2822. PCRE2_PARTIAL_HARD
  2823. PCRE2_PARTIAL_SOFT
  2824. .sp
  2825. These options turn on the partial matching feature. A partial match occurs if
  2826. the end of the subject string is reached successfully, but there are not enough
  2827. subject characters to complete the match. In addition, either at least one
  2828. character must have been inspected or the pattern must contain a lookbehind, or
  2829. the pattern must be one that could match an empty string.
  2830. .P
  2831. If this situation arises when PCRE2_PARTIAL_SOFT (but not PCRE2_PARTIAL_HARD)
  2832. is set, matching continues by testing any remaining alternatives. Only if no
  2833. complete match can be found is PCRE2_ERROR_PARTIAL returned instead of
  2834. PCRE2_ERROR_NOMATCH. In other words, PCRE2_PARTIAL_SOFT specifies that the
  2835. caller is prepared to handle a partial match, but only if no complete match can
  2836. be found.
  2837. .P
  2838. If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this case, if
  2839. a partial match is found, \fBpcre2_match()\fP immediately returns
  2840. PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other
  2841. words, when PCRE2_PARTIAL_HARD is set, a partial match is considered to be more
  2842. important that an alternative complete match.
  2843. .P
  2844. There is a more detailed discussion of partial and multi-segment matching, with
  2845. examples, in the
  2846. .\" HREF
  2847. \fBpcre2partial\fP
  2848. .\"
  2849. documentation.
  2850. .
  2851. .
  2852. .
  2853. .SH "NEWLINE HANDLING WHEN MATCHING"
  2854. .rs
  2855. .sp
  2856. When PCRE2 is built, a default newline convention is set; this is usually the
  2857. standard convention for the operating system. The default can be overridden in
  2858. a
  2859. .\" HTML <a href="#compilecontext">
  2860. .\" </a>
  2861. compile context
  2862. .\"
  2863. by calling \fBpcre2_set_newline()\fP. It can also be overridden by starting a
  2864. pattern string with, for example, (*CRLF), as described in the
  2865. .\" HTML <a href="pcre2pattern.html#newlines">
  2866. .\" </a>
  2867. section on newline conventions
  2868. .\"
  2869. in the
  2870. .\" HREF
  2871. \fBpcre2pattern\fP
  2872. .\"
  2873. page. During matching, the newline choice affects the behaviour of the dot,
  2874. circumflex, and dollar metacharacters. It may also alter the way the match
  2875. starting position is advanced after a match failure for an unanchored pattern.
  2876. .P
  2877. When PCRE2_NEWLINE_CRLF, PCRE2_NEWLINE_ANYCRLF, or PCRE2_NEWLINE_ANY is set as
  2878. the newline convention, and a match attempt for an unanchored pattern fails
  2879. when the current starting position is at a CRLF sequence, and the pattern
  2880. contains no explicit matches for CR or LF characters, the match position is
  2881. advanced by two characters instead of one, in other words, to after the CRLF.
  2882. .P
  2883. The above rule is a compromise that makes the most common cases work as
  2884. expected. For example, if the pattern is .+A (and the PCRE2_DOTALL option is
  2885. not set), it does not match the string "\er\enA" because, after failing at the
  2886. start, it skips both the CR and the LF before retrying. However, the pattern
  2887. [\er\en]A does match that string, because it contains an explicit CR or LF
  2888. reference, and so advances only by one character after the first failure.
  2889. .P
  2890. An explicit match for CR of LF is either a literal appearance of one of those
  2891. characters in the pattern, or one of the \er or \en or equivalent octal or
  2892. hexadecimal escape sequences. Implicit matches such as [^X] do not count, nor
  2893. does \es, even though it includes CR and LF in the characters that it matches.
  2894. .P
  2895. Notwithstanding the above, anomalous effects may still occur when CRLF is a
  2896. valid newline sequence and explicit \er or \en escapes appear in the pattern.
  2897. .
  2898. .
  2899. .\" HTML <a name="matchedstrings"></a>
  2900. .SH "HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS"
  2901. .rs
  2902. .sp
  2903. .nf
  2904. .B uint32_t pcre2_get_ovector_count(pcre2_match_data *\fImatch_data\fP);
  2905. .sp
  2906. .B PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *\fImatch_data\fP);
  2907. .fi
  2908. .P
  2909. In general, a pattern matches a certain portion of the subject, and in
  2910. addition, further substrings from the subject may be picked out by
  2911. parenthesized parts of the pattern. Following the usage in Jeffrey Friedl's
  2912. book, this is called "capturing" in what follows, and the phrase "capture
  2913. group" (Perl terminology) is used for a fragment of a pattern that picks out a
  2914. substring. PCRE2 supports several other kinds of parenthesized group that do
  2915. not cause substrings to be captured. The \fBpcre2_pattern_info()\fP function
  2916. can be used to find out how many capture groups there are in a compiled
  2917. pattern.
  2918. .P
  2919. You can use auxiliary functions for accessing captured substrings
  2920. .\" HTML <a href="#extractbynumber">
  2921. .\" </a>
  2922. by number
  2923. .\"
  2924. or
  2925. .\" HTML <a href="#extractbyname">
  2926. .\" </a>
  2927. by name,
  2928. .\"
  2929. as described in sections below.
  2930. .P
  2931. Alternatively, you can make direct use of the vector of PCRE2_SIZE values,
  2932. called the \fBovector\fP, which contains the offsets of captured strings. It is
  2933. part of the
  2934. .\" HTML <a href="#matchdatablock">
  2935. .\" </a>
  2936. match data block.
  2937. .\"
  2938. The function \fBpcre2_get_ovector_pointer()\fP returns the address of the
  2939. ovector, and \fBpcre2_get_ovector_count()\fP returns the number of pairs of
  2940. values it contains.
  2941. .P
  2942. Within the ovector, the first in each pair of values is set to the offset of
  2943. the first code unit of a substring, and the second is set to the offset of the
  2944. first code unit after the end of a substring. These values are always code unit
  2945. offsets, not character offsets. That is, they are byte offsets in the 8-bit
  2946. library, 16-bit offsets in the 16-bit library, and 32-bit offsets in the 32-bit
  2947. library.
  2948. .P
  2949. After a partial match (error return PCRE2_ERROR_PARTIAL), only the first pair
  2950. of offsets (that is, \fIovector[0]\fP and \fIovector[1]\fP) are set. They
  2951. identify the part of the subject that was partially matched. See the
  2952. .\" HREF
  2953. \fBpcre2partial\fP
  2954. .\"
  2955. documentation for details of partial matching.
  2956. .P
  2957. After a fully successful match, the first pair of offsets identifies the
  2958. portion of the subject string that was matched by the entire pattern. The next
  2959. pair is used for the first captured substring, and so on. The value returned by
  2960. \fBpcre2_match()\fP is one more than the highest numbered pair that has been
  2961. set. For example, if two substrings have been captured, the returned value is
  2962. 3. If there are no captured substrings, the return value from a successful
  2963. match is 1, indicating that just the first pair of offsets has been set.
  2964. .P
  2965. If a pattern uses the \eK escape sequence within a positive assertion, the
  2966. reported start of a successful match can be greater than the end of the match.
  2967. For example, if the pattern (?=ab\eK) is matched against "ab", the start and
  2968. end offset values for the match are 2 and 0.
  2969. .P
  2970. If a capture group is matched repeatedly within a single match operation, it is
  2971. the last portion of the subject that it matched that is returned.
  2972. .P
  2973. If the ovector is too small to hold all the captured substring offsets, as much
  2974. as possible is filled in, and the function returns a value of zero. If captured
  2975. substrings are not of interest, \fBpcre2_match()\fP may be called with a match
  2976. data block whose ovector is of minimum length (that is, one pair).
  2977. .P
  2978. It is possible for capture group number \fIn+1\fP to match some part of the
  2979. subject when group \fIn\fP has not been used at all. For example, if the string
  2980. "abc" is matched against the pattern (a|(z))(bc) the return from the function
  2981. is 4, and groups 1 and 3 are matched, but 2 is not. When this happens, both
  2982. values in the offset pairs corresponding to unused groups are set to
  2983. PCRE2_UNSET.
  2984. .P
  2985. Offset values that correspond to unused groups at the end of the expression are
  2986. also set to PCRE2_UNSET. For example, if the string "abc" is matched against
  2987. the pattern (abc)(x(yz)?)? groups 2 and 3 are not matched. The return from the
  2988. function is 2, because the highest used capture group number is 1. The offsets
  2989. for for the second and third capture groupss (assuming the vector is large
  2990. enough, of course) are set to PCRE2_UNSET.
  2991. .P
  2992. Elements in the ovector that do not correspond to capturing parentheses in the
  2993. pattern are never changed. That is, if a pattern contains \fIn\fP capturing
  2994. parentheses, no more than \fIovector[0]\fP to \fIovector[2n+1]\fP are set by
  2995. \fBpcre2_match()\fP. The other elements retain whatever values they previously
  2996. had. After a failed match attempt, the contents of the ovector are unchanged.
  2997. .
  2998. .
  2999. .\" HTML <a name="matchotherdata"></a>
  3000. .SH "OTHER INFORMATION ABOUT A MATCH"
  3001. .rs
  3002. .sp
  3003. .nf
  3004. .B PCRE2_SPTR pcre2_get_mark(pcre2_match_data *\fImatch_data\fP);
  3005. .sp
  3006. .B PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *\fImatch_data\fP);
  3007. .fi
  3008. .P
  3009. As well as the offsets in the ovector, other information about a match is
  3010. retained in the match data block and can be retrieved by the above functions in
  3011. appropriate circumstances. If they are called at other times, the result is
  3012. undefined.
  3013. .P
  3014. After a successful match, a partial match (PCRE2_ERROR_PARTIAL), or a failure
  3015. to match (PCRE2_ERROR_NOMATCH), a mark name may be available. The function
  3016. \fBpcre2_get_mark()\fP can be called to access this name, which can be
  3017. specified in the pattern by any of the backtracking control verbs, not just
  3018. (*MARK). The same function applies to all the verbs. It returns a pointer to
  3019. the zero-terminated name, which is within the compiled pattern. If no name is
  3020. available, NULL is returned. The length of the name (excluding the terminating
  3021. zero) is stored in the code unit that precedes the name. You should use this
  3022. length instead of relying on the terminating zero if the name might contain a
  3023. binary zero.
  3024. .P
  3025. After a successful match, the name that is returned is the last mark name
  3026. encountered on the matching path through the pattern. Instances of backtracking
  3027. verbs without names do not count. Thus, for example, if the matching path
  3028. contains (*MARK:A)(*PRUNE), the name "A" is returned. After a "no match" or a
  3029. partial match, the last encountered name is returned. For example, consider
  3030. this pattern:
  3031. .sp
  3032. ^(*MARK:A)((*MARK:B)a|b)c
  3033. .sp
  3034. When it matches "bc", the returned name is A. The B mark is "seen" in the first
  3035. branch of the group, but it is not on the matching path. On the other hand,
  3036. when this pattern fails to match "bx", the returned name is B.
  3037. .P
  3038. \fBWarning:\fP By default, certain start-of-match optimizations are used to
  3039. give a fast "no match" result in some situations. For example, if the anchoring
  3040. is removed from the pattern above, there is an initial check for the presence
  3041. of "c" in the subject before running the matching engine. This check fails for
  3042. "bx", causing a match failure without seeing any marks. You can disable the
  3043. start-of-match optimizations by setting the PCRE2_NO_START_OPTIMIZE option for
  3044. \fBpcre2_compile()\fP or by starting the pattern with (*NO_START_OPT).
  3045. .P
  3046. After a successful match, a partial match, or one of the invalid UTF errors
  3047. (for example, PCRE2_ERROR_UTF8_ERR5), \fBpcre2_get_startchar()\fP can be
  3048. called. After a successful or partial match it returns the code unit offset of
  3049. the character at which the match started. For a non-partial match, this can be
  3050. different to the value of \fIovector[0]\fP if the pattern contains the \eK
  3051. escape sequence. After a partial match, however, this value is always the same
  3052. as \fIovector[0]\fP because \eK does not affect the result of a partial match.
  3053. .P
  3054. After a UTF check failure, \fBpcre2_get_startchar()\fP can be used to obtain
  3055. the code unit offset of the invalid UTF character. Details are given in the
  3056. .\" HREF
  3057. \fBpcre2unicode\fP
  3058. .\"
  3059. page.
  3060. .
  3061. .
  3062. .\" HTML <a name="errorlist"></a>
  3063. .SH "ERROR RETURNS FROM \fBpcre2_match()\fP"
  3064. .rs
  3065. .sp
  3066. If \fBpcre2_match()\fP fails, it returns a negative number. This can be
  3067. converted to a text string by calling the \fBpcre2_get_error_message()\fP
  3068. function (see "Obtaining a textual error message"
  3069. .\" HTML <a href="#geterrormessage">
  3070. .\" </a>
  3071. below).
  3072. .\"
  3073. Negative error codes are also returned by other functions, and are documented
  3074. with them. The codes are given names in the header file. If UTF checking is in
  3075. force and an invalid UTF subject string is detected, one of a number of
  3076. UTF-specific negative error codes is returned. Details are given in the
  3077. .\" HREF
  3078. \fBpcre2unicode\fP
  3079. .\"
  3080. page. The following are the other errors that may be returned by
  3081. \fBpcre2_match()\fP:
  3082. .sp
  3083. PCRE2_ERROR_NOMATCH
  3084. .sp
  3085. The subject string did not match the pattern.
  3086. .sp
  3087. PCRE2_ERROR_PARTIAL
  3088. .sp
  3089. The subject string did not match, but it did match partially. See the
  3090. .\" HREF
  3091. \fBpcre2partial\fP
  3092. .\"
  3093. documentation for details of partial matching.
  3094. .sp
  3095. PCRE2_ERROR_BADMAGIC
  3096. .sp
  3097. PCRE2 stores a 4-byte "magic number" at the start of the compiled code, to
  3098. catch the case when it is passed a junk pointer. This is the error that is
  3099. returned when the magic number is not present.
  3100. .sp
  3101. PCRE2_ERROR_BADMODE
  3102. .sp
  3103. This error is given when a compiled pattern is passed to a function in a
  3104. library of a different code unit width, for example, a pattern compiled by
  3105. the 8-bit library is passed to a 16-bit or 32-bit library function.
  3106. .sp
  3107. PCRE2_ERROR_BADOFFSET
  3108. .sp
  3109. The value of \fIstartoffset\fP was greater than the length of the subject.
  3110. .sp
  3111. PCRE2_ERROR_BADOPTION
  3112. .sp
  3113. An unrecognized bit was set in the \fIoptions\fP argument.
  3114. .sp
  3115. PCRE2_ERROR_BADUTFOFFSET
  3116. .sp
  3117. The UTF code unit sequence that was passed as a subject was checked and found
  3118. to be valid (the PCRE2_NO_UTF_CHECK option was not set), but the value of
  3119. \fIstartoffset\fP did not point to the beginning of a UTF character or the end
  3120. of the subject.
  3121. .sp
  3122. PCRE2_ERROR_CALLOUT
  3123. .sp
  3124. This error is never generated by \fBpcre2_match()\fP itself. It is provided for
  3125. use by callout functions that want to cause \fBpcre2_match()\fP or
  3126. \fBpcre2_callout_enumerate()\fP to return a distinctive error code. See the
  3127. .\" HREF
  3128. \fBpcre2callout\fP
  3129. .\"
  3130. documentation for details.
  3131. .sp
  3132. PCRE2_ERROR_DEPTHLIMIT
  3133. .sp
  3134. The nested backtracking depth limit was reached.
  3135. .sp
  3136. PCRE2_ERROR_HEAPLIMIT
  3137. .sp
  3138. The heap limit was reached.
  3139. .sp
  3140. PCRE2_ERROR_INTERNAL
  3141. .sp
  3142. An unexpected internal error has occurred. This error could be caused by a bug
  3143. in PCRE2 or by overwriting of the compiled pattern.
  3144. .sp
  3145. PCRE2_ERROR_JIT_STACKLIMIT
  3146. .sp
  3147. This error is returned when a pattern that was successfully studied using JIT
  3148. is being matched, but the memory available for the just-in-time processing
  3149. stack is not large enough. See the
  3150. .\" HREF
  3151. \fBpcre2jit\fP
  3152. .\"
  3153. documentation for more details.
  3154. .sp
  3155. PCRE2_ERROR_MATCHLIMIT
  3156. .sp
  3157. The backtracking match limit was reached.
  3158. .sp
  3159. PCRE2_ERROR_NOMEMORY
  3160. .sp
  3161. If a pattern contains many nested backtracking points, heap memory is used to
  3162. remember them. This error is given when the memory allocation function (default
  3163. or custom) fails. Note that a different error, PCRE2_ERROR_HEAPLIMIT, is given
  3164. if the amount of memory needed exceeds the heap limit. PCRE2_ERROR_NOMEMORY is
  3165. also returned if PCRE2_COPY_MATCHED_SUBJECT is set and memory allocation fails.
  3166. .sp
  3167. PCRE2_ERROR_NULL
  3168. .sp
  3169. Either the \fIcode\fP, \fIsubject\fP, or \fImatch_data\fP argument was passed
  3170. as NULL.
  3171. .sp
  3172. PCRE2_ERROR_RECURSELOOP
  3173. .sp
  3174. This error is returned when \fBpcre2_match()\fP detects a recursion loop within
  3175. the pattern. Specifically, it means that either the whole pattern or a
  3176. capture group has been called recursively for the second time at the same
  3177. position in the subject string. Some simple patterns that might do this are
  3178. detected and faulted at compile time, but more complicated cases, in particular
  3179. mutual recursions between two different groups, cannot be detected until
  3180. matching is attempted.
  3181. .
  3182. .
  3183. .\" HTML <a name="geterrormessage"></a>
  3184. .SH "OBTAINING A TEXTUAL ERROR MESSAGE"
  3185. .rs
  3186. .sp
  3187. .nf
  3188. .B int pcre2_get_error_message(int \fIerrorcode\fP, PCRE2_UCHAR *\fIbuffer\fP,
  3189. .B " PCRE2_SIZE \fIbufflen\fP);"
  3190. .fi
  3191. .P
  3192. A text message for an error code from any PCRE2 function (compile, match, or
  3193. auxiliary) can be obtained by calling \fBpcre2_get_error_message()\fP. The code
  3194. is passed as the first argument, with the remaining two arguments specifying a
  3195. code unit buffer and its length in code units, into which the text message is
  3196. placed. The message is returned in code units of the appropriate width for the
  3197. library that is being used.
  3198. .P
  3199. The returned message is terminated with a trailing zero, and the function
  3200. returns the number of code units used, excluding the trailing zero. If the
  3201. error number is unknown, the negative error code PCRE2_ERROR_BADDATA is
  3202. returned. If the buffer is too small, the message is truncated (but still with
  3203. a trailing zero), and the negative error code PCRE2_ERROR_NOMEMORY is returned.
  3204. None of the messages are very long; a buffer size of 120 code units is ample.
  3205. .
  3206. .
  3207. .\" HTML <a name="extractbynumber"></a>
  3208. .SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER"
  3209. .rs
  3210. .sp
  3211. .nf
  3212. .B int pcre2_substring_length_bynumber(pcre2_match_data *\fImatch_data\fP,
  3213. .B " uint32_t \fInumber\fP, PCRE2_SIZE *\fIlength\fP);"
  3214. .sp
  3215. .B int pcre2_substring_copy_bynumber(pcre2_match_data *\fImatch_data\fP,
  3216. .B " uint32_t \fInumber\fP, PCRE2_UCHAR *\fIbuffer\fP,"
  3217. .B " PCRE2_SIZE *\fIbufflen\fP);"
  3218. .sp
  3219. .B int pcre2_substring_get_bynumber(pcre2_match_data *\fImatch_data\fP,
  3220. .B " uint32_t \fInumber\fP, PCRE2_UCHAR **\fIbufferptr\fP,"
  3221. .B " PCRE2_SIZE *\fIbufflen\fP);"
  3222. .sp
  3223. .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP);
  3224. .fi
  3225. .P
  3226. Captured substrings can be accessed directly by using the ovector as described
  3227. .\" HTML <a href="#matchedstrings">
  3228. .\" </a>
  3229. above.
  3230. .\"
  3231. For convenience, auxiliary functions are provided for extracting captured
  3232. substrings as new, separate, zero-terminated strings. A substring that contains
  3233. a binary zero is correctly extracted and has a further zero added on the end,
  3234. but the result is not, of course, a C string.
  3235. .P
  3236. The functions in this section identify substrings by number. The number zero
  3237. refers to the entire matched substring, with higher numbers referring to
  3238. substrings captured by parenthesized groups. After a partial match, only
  3239. substring zero is available. An attempt to extract any other substring gives
  3240. the error PCRE2_ERROR_PARTIAL. The next section describes similar functions for
  3241. extracting captured substrings by name.
  3242. .P
  3243. If a pattern uses the \eK escape sequence within a positive assertion, the
  3244. reported start of a successful match can be greater than the end of the match.
  3245. For example, if the pattern (?=ab\eK) is matched against "ab", the start and
  3246. end offset values for the match are 2 and 0. In this situation, calling these
  3247. functions with a zero substring number extracts a zero-length empty string.
  3248. .P
  3249. You can find the length in code units of a captured substring without
  3250. extracting it by calling \fBpcre2_substring_length_bynumber()\fP. The first
  3251. argument is a pointer to the match data block, the second is the group number,
  3252. and the third is a pointer to a variable into which the length is placed. If
  3253. you just want to know whether or not the substring has been captured, you can
  3254. pass the third argument as NULL.
  3255. .P
  3256. The \fBpcre2_substring_copy_bynumber()\fP function copies a captured substring
  3257. into a supplied buffer, whereas \fBpcre2_substring_get_bynumber()\fP copies it
  3258. into new memory, obtained using the same memory allocation function that was
  3259. used for the match data block. The first two arguments of these functions are a
  3260. pointer to the match data block and a capture group number.
  3261. .P
  3262. The final arguments of \fBpcre2_substring_copy_bynumber()\fP are a pointer to
  3263. the buffer and a pointer to a variable that contains its length in code units.
  3264. This is updated to contain the actual number of code units used for the
  3265. extracted substring, excluding the terminating zero.
  3266. .P
  3267. For \fBpcre2_substring_get_bynumber()\fP the third and fourth arguments point
  3268. to variables that are updated with a pointer to the new memory and the number
  3269. of code units that comprise the substring, again excluding the terminating
  3270. zero. When the substring is no longer needed, the memory should be freed by
  3271. calling \fBpcre2_substring_free()\fP.
  3272. .P
  3273. The return value from all these functions is zero for success, or a negative
  3274. error code. If the pattern match failed, the match failure code is returned.
  3275. If a substring number greater than zero is used after a partial match,
  3276. PCRE2_ERROR_PARTIAL is returned. Other possible error codes are:
  3277. .sp
  3278. PCRE2_ERROR_NOMEMORY
  3279. .sp
  3280. The buffer was too small for \fBpcre2_substring_copy_bynumber()\fP, or the
  3281. attempt to get memory failed for \fBpcre2_substring_get_bynumber()\fP.
  3282. .sp
  3283. PCRE2_ERROR_NOSUBSTRING
  3284. .sp
  3285. There is no substring with that number in the pattern, that is, the number is
  3286. greater than the number of capturing parentheses.
  3287. .sp
  3288. PCRE2_ERROR_UNAVAILABLE
  3289. .sp
  3290. The substring number, though not greater than the number of captures in the
  3291. pattern, is greater than the number of slots in the ovector, so the substring
  3292. could not be captured.
  3293. .sp
  3294. PCRE2_ERROR_UNSET
  3295. .sp
  3296. The substring did not participate in the match. For example, if the pattern is
  3297. (abc)|(def) and the subject is "def", and the ovector contains at least two
  3298. capturing slots, substring number 1 is unset.
  3299. .
  3300. .
  3301. .SH "EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS"
  3302. .rs
  3303. .sp
  3304. .nf
  3305. .B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP,
  3306. .B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP);
  3307. .sp
  3308. .B void pcre2_substring_list_free(PCRE2_SPTR *\fIlist\fP);
  3309. .fi
  3310. .P
  3311. The \fBpcre2_substring_list_get()\fP function extracts all available substrings
  3312. and builds a list of pointers to them. It also (optionally) builds a second
  3313. list that contains their lengths (in code units), excluding a terminating zero
  3314. that is added to each of them. All this is done in a single block of memory
  3315. that is obtained using the same memory allocation function that was used to get
  3316. the match data block.
  3317. .P
  3318. This function must be called only after a successful match. If called after a
  3319. partial match, the error code PCRE2_ERROR_PARTIAL is returned.
  3320. .P
  3321. The address of the memory block is returned via \fIlistptr\fP, which is also
  3322. the start of the list of string pointers. The end of the list is marked by a
  3323. NULL pointer. The address of the list of lengths is returned via
  3324. \fIlengthsptr\fP. If your strings do not contain binary zeros and you do not
  3325. therefore need the lengths, you may supply NULL as the \fBlengthsptr\fP
  3326. argument to disable the creation of a list of lengths. The yield of the
  3327. function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the memory block
  3328. could not be obtained. When the list is no longer needed, it should be freed by
  3329. calling \fBpcre2_substring_list_free()\fP.
  3330. .P
  3331. If this function encounters a substring that is unset, which can happen when
  3332. capture group number \fIn+1\fP matches some part of the subject, but group
  3333. \fIn\fP has not been used at all, it returns an empty string. This can be
  3334. distinguished from a genuine zero-length substring by inspecting the
  3335. appropriate offset in the ovector, which contain PCRE2_UNSET for unset
  3336. substrings, or by calling \fBpcre2_substring_length_bynumber()\fP.
  3337. .
  3338. .
  3339. .\" HTML <a name="extractbyname"></a>
  3340. .SH "EXTRACTING CAPTURED SUBSTRINGS BY NAME"
  3341. .rs
  3342. .sp
  3343. .nf
  3344. .B int pcre2_substring_number_from_name(const pcre2_code *\fIcode\fP,
  3345. .B " PCRE2_SPTR \fIname\fP);"
  3346. .sp
  3347. .B int pcre2_substring_length_byname(pcre2_match_data *\fImatch_data\fP,
  3348. .B " PCRE2_SPTR \fIname\fP, PCRE2_SIZE *\fIlength\fP);"
  3349. .sp
  3350. .B int pcre2_substring_copy_byname(pcre2_match_data *\fImatch_data\fP,
  3351. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR *\fIbuffer\fP, PCRE2_SIZE *\fIbufflen\fP);"
  3352. .sp
  3353. .B int pcre2_substring_get_byname(pcre2_match_data *\fImatch_data\fP,
  3354. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR **\fIbufferptr\fP, PCRE2_SIZE *\fIbufflen\fP);"
  3355. .sp
  3356. .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP);
  3357. .fi
  3358. .P
  3359. To extract a substring by name, you first have to find associated number.
  3360. For example, for this pattern:
  3361. .sp
  3362. (a+)b(?<xxx>\ed+)...
  3363. .sp
  3364. the number of the capture group called "xxx" is 2. If the name is known to be
  3365. unique (PCRE2_DUPNAMES was not set), you can find the number from the name by
  3366. calling \fBpcre2_substring_number_from_name()\fP. The first argument is the
  3367. compiled pattern, and the second is the name. The yield of the function is the
  3368. group number, PCRE2_ERROR_NOSUBSTRING if there is no group with that name, or
  3369. PCRE2_ERROR_NOUNIQUESUBSTRING if there is more than one group with that name.
  3370. Given the number, you can extract the substring directly from the ovector, or
  3371. use one of the "bynumber" functions described above.
  3372. .P
  3373. For convenience, there are also "byname" functions that correspond to the
  3374. "bynumber" functions, the only difference being that the second argument is a
  3375. name instead of a number. If PCRE2_DUPNAMES is set and there are duplicate
  3376. names, these functions scan all the groups with the given name, and return the
  3377. captured substring from the first named group that is set.
  3378. .P
  3379. If there are no groups with the given name, PCRE2_ERROR_NOSUBSTRING is
  3380. returned. If all groups with the name have numbers that are greater than the
  3381. number of slots in the ovector, PCRE2_ERROR_UNAVAILABLE is returned. If there
  3382. is at least one group with a slot in the ovector, but no group is found to be
  3383. set, PCRE2_ERROR_UNSET is returned.
  3384. .P
  3385. \fBWarning:\fP If the pattern uses the (?| feature to set up multiple
  3386. capture groups with the same number, as described in the
  3387. .\" HTML <a href="pcre2pattern.html#dupgroupnumber">
  3388. .\" </a>
  3389. section on duplicate group numbers
  3390. .\"
  3391. in the
  3392. .\" HREF
  3393. \fBpcre2pattern\fP
  3394. .\"
  3395. page, you cannot use names to distinguish the different capture groups, because
  3396. names are not included in the compiled code. The matching process uses only
  3397. numbers. For this reason, the use of different names for groups with the
  3398. same number causes an error at compile time.
  3399. .
  3400. .
  3401. .\" HTML <a name="substitutions"></a>
  3402. .SH "CREATING A NEW STRING WITH SUBSTITUTIONS"
  3403. .rs
  3404. .sp
  3405. .nf
  3406. .B int pcre2_substitute(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  3407. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  3408. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  3409. .B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacement\fP,"
  3410. .B " PCRE2_SIZE \fIrlength\fP, PCRE2_UCHAR *\fIoutputbuffer\fP,"
  3411. .B " PCRE2_SIZE *\fIoutlengthptr\fP);"
  3412. .fi
  3413. .P
  3414. This function optionally calls \fBpcre2_match()\fP and then makes a copy of the
  3415. subject string in \fIoutputbuffer\fP, replacing parts that were matched with
  3416. the \fIreplacement\fP string, whose length is supplied in \fBrlength\fP. This
  3417. can be given as PCRE2_ZERO_TERMINATED for a zero-terminated string. There is an
  3418. option (see PCRE2_SUBSTITUTE_REPLACEMENT_ONLY below) to return just the
  3419. replacement string(s). The default action is to perform just one replacement if
  3420. the pattern matches, but there is an option that requests multiple replacements
  3421. (see PCRE2_SUBSTITUTE_GLOBAL below).
  3422. .P
  3423. If successful, \fBpcre2_substitute()\fP returns the number of substitutions
  3424. that were carried out. This may be zero if no match was found, and is never
  3425. greater than one unless PCRE2_SUBSTITUTE_GLOBAL is set. A negative value is
  3426. returned if an error is detected.
  3427. .P
  3428. Matches in which a \eK item in a lookahead in the pattern causes the match to
  3429. end before it starts are not supported, and give rise to an error return. For
  3430. global replacements, matches in which \eK in a lookbehind causes the match to
  3431. start earlier than the point that was reached in the previous iteration are
  3432. also not supported.
  3433. .P
  3434. The first seven arguments of \fBpcre2_substitute()\fP are the same as for
  3435. \fBpcre2_match()\fP, except that the partial matching options are not
  3436. permitted, and \fImatch_data\fP may be passed as NULL, in which case a match
  3437. data block is obtained and freed within this function, using memory management
  3438. functions from the match context, if provided, or else those that were used to
  3439. allocate memory for the compiled code.
  3440. .P
  3441. If \fImatch_data\fP is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the
  3442. provided block is used for all calls to \fBpcre2_match()\fP, and its contents
  3443. afterwards are the result of the final call. For global changes, this will
  3444. always be a no-match error. The contents of the ovector within the match data
  3445. block may or may not have been changed.
  3446. .P
  3447. As well as the usual options for \fBpcre2_match()\fP, a number of additional
  3448. options can be set in the \fIoptions\fP argument of \fBpcre2_substitute()\fP.
  3449. One such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external
  3450. \fImatch_data\fP block must be provided, and it must have been used for an
  3451. external call to \fBpcre2_match()\fP. The data in the \fImatch_data\fP block
  3452. (return code, offset vector) is used for the first substitution instead of
  3453. calling \fBpcre2_match()\fP from within \fBpcre2_substitute()\fP. This allows
  3454. an application to check for a match before choosing to substitute, without
  3455. having to repeat the match.
  3456. .P
  3457. The contents of the externally supplied match data block are not changed when
  3458. PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTITUTE_GLOBAL is also set,
  3459. \fBpcre2_match()\fP is called after the first substitution to check for further
  3460. matches, but this is done using an internally obtained match data block, thus
  3461. always leaving the external block unchanged.
  3462. .P
  3463. The \fIcode\fP argument is not used for matching before the first substitution
  3464. when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, even when
  3465. PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains information such as the
  3466. UTF setting and the number of capturing parentheses in the pattern.
  3467. .P
  3468. The default action of \fBpcre2_substitute()\fP is to return a copy of the
  3469. subject string with matched substrings replaced. However, if
  3470. PCRE2_SUBSTITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are
  3471. returned. In the global case, multiple replacements are concatenated in the
  3472. output buffer. Substitution callouts (see
  3473. .\" HTML <a href="#subcallouts">
  3474. .\" </a>
  3475. below)
  3476. .\"
  3477. can be used to separate them if necessary.
  3478. .P
  3479. The \fIoutlengthptr\fP argument of \fBpcre2_substitute()\fP must point to a
  3480. variable that contains the length, in code units, of the output buffer. If the
  3481. function is successful, the value is updated to contain the length in code
  3482. units of the new string, excluding the trailing zero that is automatically
  3483. added.
  3484. .P
  3485. If the function is not successful, the value set via \fIoutlengthptr\fP depends
  3486. on the type of error. For syntax errors in the replacement string, the value is
  3487. the offset in the replacement string where the error was detected. For other
  3488. errors, the value is PCRE2_UNSET by default. This includes the case of the
  3489. output buffer being too small, unless PCRE2_SUBSTITUTE_OVERFLOW_LENGTH is set.
  3490. .P
  3491. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH changes what happens when the output buffer is
  3492. too small. The default action is to return PCRE2_ERROR_NOMEMORY immediately. If
  3493. this option is set, however, \fBpcre2_substitute()\fP continues to go through
  3494. the motions of matching and substituting (without, of course, writing anything)
  3495. in order to compute the size of buffer that is needed. This value is passed
  3496. back via the \fIoutlengthptr\fP variable, with the result of the function still
  3497. being PCRE2_ERROR_NOMEMORY.
  3498. .P
  3499. Passing a buffer size of zero is a permitted way of finding out how much memory
  3500. is needed for given substitution. However, this does mean that the entire
  3501. operation is carried out twice. Depending on the application, it may be more
  3502. efficient to allocate a large buffer and free the excess afterwards, instead of
  3503. using PCRE2_SUBSTITUTE_OVERFLOW_LENGTH.
  3504. .P
  3505. The replacement string, which is interpreted as a UTF string in UTF mode, is
  3506. checked for UTF validity unless PCRE2_NO_UTF_CHECK is set. An invalid UTF
  3507. replacement string causes an immediate return with the relevant UTF error code.
  3508. .P
  3509. If PCRE2_SUBSTITUTE_LITERAL is set, the replacement string is not interpreted
  3510. in any way. By default, however, a dollar character is an escape character that
  3511. can specify the insertion of characters from capture groups and names from
  3512. (*MARK) or other control verbs in the pattern. The following forms are always
  3513. recognized:
  3514. .sp
  3515. $$ insert a dollar character
  3516. $<n> or ${<n>} insert the contents of group <n>
  3517. $*MARK or ${*MARK} insert a control verb name
  3518. .sp
  3519. Either a group number or a group name can be given for <n>. Curly brackets are
  3520. required only if the following character would be interpreted as part of the
  3521. number or name. The number may be zero to include the entire matched string.
  3522. For example, if the pattern a(b)c is matched with "=abc=" and the replacement
  3523. string "+$1$0$1+", the result is "=+babcb+=".
  3524. .P
  3525. $*MARK inserts the name from the last encountered backtracking control verb on
  3526. the matching path that has a name. (*MARK) must always include a name, but the
  3527. other verbs need not. For example, in the case of (*MARK:A)(*PRUNE) the name
  3528. inserted is "A", but for (*MARK:A)(*PRUNE:B) the relevant name is "B". This
  3529. facility can be used to perform simple simultaneous substitutions, as this
  3530. \fBpcre2test\fP example shows:
  3531. .sp
  3532. /(*MARK:pear)apple|(*MARK:orange)lemon/g,replace=${*MARK}
  3533. apple lemon
  3534. 2: pear orange
  3535. .sp
  3536. PCRE2_SUBSTITUTE_GLOBAL causes the function to iterate over the subject string,
  3537. replacing every matching substring. If this option is not set, only the first
  3538. matching substring is replaced. The search for matches takes place in the
  3539. original subject string (that is, previous replacements do not affect it).
  3540. Iteration is implemented by advancing the \fIstartoffset\fP value for each
  3541. search, which is always passed the entire subject string. If an offset limit is
  3542. set in the match context, searching stops when that limit is reached.
  3543. .P
  3544. You can restrict the effect of a global substitution to a portion of the
  3545. subject string by setting either or both of \fIstartoffset\fP and an offset
  3546. limit. Here is a \fBpcre2test\fP example:
  3547. .sp
  3548. /B/g,replace=!,use_offset_limit
  3549. ABC ABC ABC ABC\e=offset=3,offset_limit=12
  3550. 2: ABC A!C A!C ABC
  3551. .sp
  3552. When continuing with global substitutions after matching a substring with zero
  3553. length, an attempt to find a non-empty match at the same offset is performed.
  3554. If this is not successful, the offset is advanced by one character except when
  3555. CRLF is a valid newline sequence and the next two characters are CR, LF. In
  3556. this case, the offset is advanced by two characters.
  3557. .P
  3558. PCRE2_SUBSTITUTE_UNKNOWN_UNSET causes references to capture groups that do
  3559. not appear in the pattern to be treated as unset groups. This option should be
  3560. used with care, because it means that a typo in a group name or number no
  3561. longer causes the PCRE2_ERROR_NOSUBSTRING error.
  3562. .P
  3563. PCRE2_SUBSTITUTE_UNSET_EMPTY causes unset capture groups (including unknown
  3564. groups when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) to be treated as empty
  3565. strings when inserted as described above. If this option is not set, an attempt
  3566. to insert an unset group causes the PCRE2_ERROR_UNSET error. This option does
  3567. not influence the extended substitution syntax described below.
  3568. .P
  3569. PCRE2_SUBSTITUTE_EXTENDED causes extra processing to be applied to the
  3570. replacement string. Without this option, only the dollar character is special,
  3571. and only the group insertion forms listed above are valid. When
  3572. PCRE2_SUBSTITUTE_EXTENDED is set, two things change:
  3573. .P
  3574. Firstly, backslash in a replacement string is interpreted as an escape
  3575. character. The usual forms such as \en or \ex{ddd} can be used to specify
  3576. particular character codes, and backslash followed by any non-alphanumeric
  3577. character quotes that character. Extended quoting can be coded using \eQ...\eE,
  3578. exactly as in pattern strings.
  3579. .P
  3580. There are also four escape sequences for forcing the case of inserted letters.
  3581. The insertion mechanism has three states: no case forcing, force upper case,
  3582. and force lower case. The escape sequences change the current state: \eU and
  3583. \eL change to upper or lower case forcing, respectively, and \eE (when not
  3584. terminating a \eQ quoted sequence) reverts to no case forcing. The sequences
  3585. \eu and \el force the next character (if it is a letter) to upper or lower
  3586. case, respectively, and then the state automatically reverts to no case
  3587. forcing. Case forcing applies to all inserted characters, including those from
  3588. capture groups and letters within \eQ...\eE quoted sequences. If either
  3589. PCRE2_UTF or PCRE2_UCP was set when the pattern was compiled, Unicode
  3590. properties are used for case forcing characters whose code points are greater
  3591. than 127.
  3592. .P
  3593. Note that case forcing sequences such as \eU...\eE do not nest. For example,
  3594. the result of processing "\eUaa\eLBB\eEcc\eE" is "AAbbcc"; the final \eE has no
  3595. effect. Note also that the PCRE2_ALT_BSUX and PCRE2_EXTRA_ALT_BSUX options do
  3596. not apply to replacement strings.
  3597. .P
  3598. The second effect of setting PCRE2_SUBSTITUTE_EXTENDED is to add more
  3599. flexibility to capture group substitution. The syntax is similar to that used
  3600. by Bash:
  3601. .sp
  3602. ${<n>:-<string>}
  3603. ${<n>:+<string1>:<string2>}
  3604. .sp
  3605. As before, <n> may be a group number or a name. The first form specifies a
  3606. default value. If group <n> is set, its value is inserted; if not, <string> is
  3607. expanded and the result inserted. The second form specifies strings that are
  3608. expanded and inserted when group <n> is set or unset, respectively. The first
  3609. form is just a convenient shorthand for
  3610. .sp
  3611. ${<n>:+${<n>}:<string>}
  3612. .sp
  3613. Backslash can be used to escape colons and closing curly brackets in the
  3614. replacement strings. A change of the case forcing state within a replacement
  3615. string remains in force afterwards, as shown in this \fBpcre2test\fP example:
  3616. .sp
  3617. /(some)?(body)/substitute_extended,replace=${1:+\eU:\eL}HeLLo
  3618. body
  3619. 1: hello
  3620. somebody
  3621. 1: HELLO
  3622. .sp
  3623. The PCRE2_SUBSTITUTE_UNSET_EMPTY option does not affect these extended
  3624. substitutions. However, PCRE2_SUBSTITUTE_UNKNOWN_UNSET does cause unknown
  3625. groups in the extended syntax forms to be treated as unset.
  3626. .P
  3627. If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_UNKNOWN_UNSET,
  3628. PCRE2_SUBSTITUTE_UNSET_EMPTY, and PCRE2_SUBSTITUTE_EXTENDED are irrelevant and
  3629. are ignored.
  3630. .
  3631. .
  3632. .SS "Substitution errors"
  3633. .rs
  3634. .sp
  3635. In the event of an error, \fBpcre2_substitute()\fP returns a negative error
  3636. code. Except for PCRE2_ERROR_NOMATCH (which is never returned), errors from
  3637. \fBpcre2_match()\fP are passed straight back.
  3638. .P
  3639. PCRE2_ERROR_NOSUBSTRING is returned for a non-existent substring insertion,
  3640. unless PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set.
  3641. .P
  3642. PCRE2_ERROR_UNSET is returned for an unset substring insertion (including an
  3643. unknown substring when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) when the simple
  3644. (non-extended) syntax is used and PCRE2_SUBSTITUTE_UNSET_EMPTY is not set.
  3645. .P
  3646. PCRE2_ERROR_NOMEMORY is returned if the output buffer is not big enough. If the
  3647. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set, the size of buffer that is
  3648. needed is returned via \fIoutlengthptr\fP. Note that this does not happen by
  3649. default.
  3650. .P
  3651. PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the
  3652. \fImatch_data\fP argument is NULL.
  3653. .P
  3654. PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the
  3655. replacement string, with more particular errors being PCRE2_ERROR_BADREPESCAPE
  3656. (invalid escape sequence), PCRE2_ERROR_REPMISSINGBRACE (closing curly bracket
  3657. not found), PCRE2_ERROR_BADSUBSTITUTION (syntax error in extended group
  3658. substitution), and PCRE2_ERROR_BADSUBSPATTERN (the pattern match ended before
  3659. it started or the match started earlier than the current position in the
  3660. subject, which can happen if \eK is used in an assertion).
  3661. .P
  3662. As for all PCRE2 errors, a text message that describes the error can be
  3663. obtained by calling the \fBpcre2_get_error_message()\fP function (see
  3664. "Obtaining a textual error message"
  3665. .\" HTML <a href="#geterrormessage">
  3666. .\" </a>
  3667. above).
  3668. .\"
  3669. .
  3670. .
  3671. .\" HTML <a name="subcallouts"></a>
  3672. .SS "Substitution callouts"
  3673. .rs
  3674. .sp
  3675. .nf
  3676. .B int pcre2_set_substitute_callout(pcre2_match_context *\fImcontext\fP,
  3677. .B " int (*\fIcallout_function\fP)(pcre2_substitute_callout_block *, void *),"
  3678. .B " void *\fIcallout_data\fP);"
  3679. .fi
  3680. .sp
  3681. The \fBpcre2_set_substitution_callout()\fP function can be used to specify a
  3682. callout function for \fBpcre2_substitute()\fP. This information is passed in
  3683. a match context. The callout function is called after each substitution has
  3684. been processed, but it can cause the replacement not to happen. The callout
  3685. function is not called for simulated substitutions that happen as a result of
  3686. the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option.
  3687. .P
  3688. The first argument of the callout function is a pointer to a substitute callout
  3689. block structure, which contains the following fields, not necessarily in this
  3690. order:
  3691. .sp
  3692. uint32_t \fIversion\fP;
  3693. uint32_t \fIsubscount\fP;
  3694. PCRE2_SPTR \fIinput\fP;
  3695. PCRE2_SPTR \fIoutput\fP;
  3696. PCRE2_SIZE \fI*ovector\fP;
  3697. uint32_t \fIoveccount\fP;
  3698. PCRE2_SIZE \fIoutput_offsets[2]\fP;
  3699. .sp
  3700. The \fIversion\fP field contains the version number of the block format. The
  3701. current version is 0. The version number will increase in future if more fields
  3702. are added, but the intention is never to remove any of the existing fields.
  3703. .P
  3704. The \fIsubscount\fP field is the number of the current match. It is 1 for the
  3705. first callout, 2 for the second, and so on. The \fIinput\fP and \fIoutput\fP
  3706. pointers are copies of the values passed to \fBpcre2_substitute()\fP.
  3707. .P
  3708. The \fIovector\fP field points to the ovector, which contains the result of the
  3709. most recent match. The \fIoveccount\fP field contains the number of pairs that
  3710. are set in the ovector, and is always greater than zero.
  3711. .P
  3712. The \fIoutput_offsets\fP vector contains the offsets of the replacement in the
  3713. output string. This has already been processed for dollar and (if requested)
  3714. backslash substitutions as described above.
  3715. .P
  3716. The second argument of the callout function is the value passed as
  3717. \fIcallout_data\fP when the function was registered. The value returned by the
  3718. callout function is interpreted as follows:
  3719. .P
  3720. If the value is zero, the replacement is accepted, and, if
  3721. PCRE2_SUBSTITUTE_GLOBAL is set, processing continues with a search for the next
  3722. match. If the value is not zero, the current replacement is not accepted. If
  3723. the value is greater than zero, processing continues when
  3724. PCRE2_SUBSTITUTE_GLOBAL is set. Otherwise (the value is less than zero or
  3725. PCRE2_SUBSTITUTE_GLOBAL is not set), the the rest of the input is copied to the
  3726. output and the call to \fBpcre2_substitute()\fP exits, returning the number of
  3727. matches so far.
  3728. .
  3729. .
  3730. .SH "DUPLICATE CAPTURE GROUP NAMES"
  3731. .rs
  3732. .sp
  3733. .nf
  3734. .B int pcre2_substring_nametable_scan(const pcre2_code *\fIcode\fP,
  3735. .B " PCRE2_SPTR \fIname\fP, PCRE2_SPTR *\fIfirst\fP, PCRE2_SPTR *\fIlast\fP);"
  3736. .fi
  3737. .P
  3738. When a pattern is compiled with the PCRE2_DUPNAMES option, names for capture
  3739. groups are not required to be unique. Duplicate names are always allowed for
  3740. groups with the same number, created by using the (?| feature. Indeed, if such
  3741. groups are named, they are required to use the same names.
  3742. .P
  3743. Normally, patterns that use duplicate names are such that in any one match,
  3744. only one of each set of identically-named groups participates. An example is
  3745. shown in the
  3746. .\" HREF
  3747. \fBpcre2pattern\fP
  3748. .\"
  3749. documentation.
  3750. .P
  3751. When duplicates are present, \fBpcre2_substring_copy_byname()\fP and
  3752. \fBpcre2_substring_get_byname()\fP return the first substring corresponding to
  3753. the given name that is set. Only if none are set is PCRE2_ERROR_UNSET is
  3754. returned. The \fBpcre2_substring_number_from_name()\fP function returns the
  3755. error PCRE2_ERROR_NOUNIQUESUBSTRING when there are duplicate names.
  3756. .P
  3757. If you want to get full details of all captured substrings for a given name,
  3758. you must use the \fBpcre2_substring_nametable_scan()\fP function. The first
  3759. argument is the compiled pattern, and the second is the name. If the third and
  3760. fourth arguments are NULL, the function returns a group number for a unique
  3761. name, or PCRE2_ERROR_NOUNIQUESUBSTRING otherwise.
  3762. .P
  3763. When the third and fourth arguments are not NULL, they must be pointers to
  3764. variables that are updated by the function. After it has run, they point to the
  3765. first and last entries in the name-to-number table for the given name, and the
  3766. function returns the length of each entry in code units. In both cases,
  3767. PCRE2_ERROR_NOSUBSTRING is returned if there are no entries for the given name.
  3768. .P
  3769. The format of the name table is described
  3770. .\" HTML <a href="#infoaboutpattern">
  3771. .\" </a>
  3772. above
  3773. .\"
  3774. in the section entitled \fIInformation about a pattern\fP. Given all the
  3775. relevant entries for the name, you can extract each of their numbers, and hence
  3776. the captured data.
  3777. .
  3778. .
  3779. .SH "FINDING ALL POSSIBLE MATCHES AT ONE POSITION"
  3780. .rs
  3781. .sp
  3782. The traditional matching function uses a similar algorithm to Perl, which stops
  3783. when it finds the first match at a given point in the subject. If you want to
  3784. find all possible matches, or the longest possible match at a given position,
  3785. consider using the alternative matching function (see below) instead. If you
  3786. cannot use the alternative function, you can kludge it up by making use of the
  3787. callout facility, which is described in the
  3788. .\" HREF
  3789. \fBpcre2callout\fP
  3790. .\"
  3791. documentation.
  3792. .P
  3793. What you have to do is to insert a callout right at the end of the pattern.
  3794. When your callout function is called, extract and save the current matched
  3795. substring. Then return 1, which forces \fBpcre2_match()\fP to backtrack and try
  3796. other alternatives. Ultimately, when it runs out of matches,
  3797. \fBpcre2_match()\fP will yield PCRE2_ERROR_NOMATCH.
  3798. .
  3799. .
  3800. .\" HTML <a name="dfamatch"></a>
  3801. .SH "MATCHING A PATTERN: THE ALTERNATIVE FUNCTION"
  3802. .rs
  3803. .sp
  3804. .nf
  3805. .B int pcre2_dfa_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  3806. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  3807. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  3808. .B " pcre2_match_context *\fImcontext\fP,"
  3809. .B " int *\fIworkspace\fP, PCRE2_SIZE \fIwscount\fP);"
  3810. .fi
  3811. .P
  3812. The function \fBpcre2_dfa_match()\fP is called to match a subject string
  3813. against a compiled pattern, using a matching algorithm that scans the subject
  3814. string just once (not counting lookaround assertions), and does not backtrack.
  3815. This has different characteristics to the normal algorithm, and is not
  3816. compatible with Perl. Some of the features of PCRE2 patterns are not supported.
  3817. Nevertheless, there are times when this kind of matching can be useful. For a
  3818. discussion of the two matching algorithms, and a list of features that
  3819. \fBpcre2_dfa_match()\fP does not support, see the
  3820. .\" HREF
  3821. \fBpcre2matching\fP
  3822. .\"
  3823. documentation.
  3824. .P
  3825. The arguments for the \fBpcre2_dfa_match()\fP function are the same as for
  3826. \fBpcre2_match()\fP, plus two extras. The ovector within the match data block
  3827. is used in a different way, and this is described below. The other common
  3828. arguments are used in the same way as for \fBpcre2_match()\fP, so their
  3829. description is not repeated here.
  3830. .P
  3831. The two additional arguments provide workspace for the function. The workspace
  3832. vector should contain at least 20 elements. It is used for keeping track of
  3833. multiple paths through the pattern tree. More workspace is needed for patterns
  3834. and subjects where there are a lot of potential matches.
  3835. .P
  3836. Here is an example of a simple call to \fBpcre2_dfa_match()\fP:
  3837. .sp
  3838. int wspace[20];
  3839. pcre2_match_data *md = pcre2_match_data_create(4, NULL);
  3840. int rc = pcre2_dfa_match(
  3841. re, /* result of pcre2_compile() */
  3842. "some string", /* the subject string */
  3843. 11, /* the length of the subject string */
  3844. 0, /* start at offset 0 in the subject */
  3845. 0, /* default options */
  3846. md, /* the match data block */
  3847. NULL, /* a match context; NULL means use defaults */
  3848. wspace, /* working space vector */
  3849. 20); /* number of elements (NOT size in bytes) */
  3850. .
  3851. .SS "Option bits for \fBpcre_dfa_match()\fP"
  3852. .rs
  3853. .sp
  3854. The unused bits of the \fIoptions\fP argument for \fBpcre2_dfa_match()\fP must
  3855. be zero. The only bits that may be set are PCRE2_ANCHORED,
  3856. PCRE2_COPY_MATCHED_SUBJECT, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL,
  3857. PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_UTF_CHECK, PCRE2_PARTIAL_HARD,
  3858. PCRE2_PARTIAL_SOFT, PCRE2_DFA_SHORTEST, and PCRE2_DFA_RESTART. All but the last
  3859. four of these are exactly the same as for \fBpcre2_match()\fP, so their
  3860. description is not repeated here.
  3861. .sp
  3862. PCRE2_PARTIAL_HARD
  3863. PCRE2_PARTIAL_SOFT
  3864. .sp
  3865. These have the same general effect as they do for \fBpcre2_match()\fP, but the
  3866. details are slightly different. When PCRE2_PARTIAL_HARD is set for
  3867. \fBpcre2_dfa_match()\fP, it returns PCRE2_ERROR_PARTIAL if the end of the
  3868. subject is reached and there is still at least one matching possibility that
  3869. requires additional characters. This happens even if some complete matches have
  3870. already been found. When PCRE2_PARTIAL_SOFT is set, the return code
  3871. PCRE2_ERROR_NOMATCH is converted into PCRE2_ERROR_PARTIAL if the end of the
  3872. subject is reached, there have been no complete matches, but there is still at
  3873. least one matching possibility. The portion of the string that was inspected
  3874. when the longest partial match was found is set as the first matching string in
  3875. both cases. There is a more detailed discussion of partial and multi-segment
  3876. matching, with examples, in the
  3877. .\" HREF
  3878. \fBpcre2partial\fP
  3879. .\"
  3880. documentation.
  3881. .sp
  3882. PCRE2_DFA_SHORTEST
  3883. .sp
  3884. Setting the PCRE2_DFA_SHORTEST option causes the matching algorithm to stop as
  3885. soon as it has found one match. Because of the way the alternative algorithm
  3886. works, this is necessarily the shortest possible match at the first possible
  3887. matching point in the subject string.
  3888. .sp
  3889. PCRE2_DFA_RESTART
  3890. .sp
  3891. When \fBpcre2_dfa_match()\fP returns a partial match, it is possible to call it
  3892. again, with additional subject characters, and have it continue with the same
  3893. match. The PCRE2_DFA_RESTART option requests this action; when it is set, the
  3894. \fIworkspace\fP and \fIwscount\fP options must reference the same vector as
  3895. before because data about the match so far is left in them after a partial
  3896. match. There is more discussion of this facility in the
  3897. .\" HREF
  3898. \fBpcre2partial\fP
  3899. .\"
  3900. documentation.
  3901. .
  3902. .
  3903. .SS "Successful returns from \fBpcre2_dfa_match()\fP"
  3904. .rs
  3905. .sp
  3906. When \fBpcre2_dfa_match()\fP succeeds, it may have matched more than one
  3907. substring in the subject. Note, however, that all the matches from one run of
  3908. the function start at the same point in the subject. The shorter matches are
  3909. all initial substrings of the longer matches. For example, if the pattern
  3910. .sp
  3911. <.*>
  3912. .sp
  3913. is matched against the string
  3914. .sp
  3915. This is <something> <something else> <something further> no more
  3916. .sp
  3917. the three matched strings are
  3918. .sp
  3919. <something> <something else> <something further>
  3920. <something> <something else>
  3921. <something>
  3922. .sp
  3923. On success, the yield of the function is a number greater than zero, which is
  3924. the number of matched substrings. The offsets of the substrings are returned in
  3925. the ovector, and can be extracted by number in the same way as for
  3926. \fBpcre2_match()\fP, but the numbers bear no relation to any capture groups
  3927. that may exist in the pattern, because DFA matching does not support capturing.
  3928. .P
  3929. Calls to the convenience functions that extract substrings by name
  3930. return the error PCRE2_ERROR_DFA_UFUNC (unsupported function) if used after a
  3931. DFA match. The convenience functions that extract substrings by number never
  3932. return PCRE2_ERROR_NOSUBSTRING.
  3933. .P
  3934. The matched strings are stored in the ovector in reverse order of length; that
  3935. is, the longest matching string is first. If there were too many matches to fit
  3936. into the ovector, the yield of the function is zero, and the vector is filled
  3937. with the longest matches.
  3938. .P
  3939. NOTE: PCRE2's "auto-possessification" optimization usually applies to character
  3940. repeats at the end of a pattern (as well as internally). For example, the
  3941. pattern "a\ed+" is compiled as if it were "a\ed++". For DFA matching, this
  3942. means that only one possible match is found. If you really do want multiple
  3943. matches in such cases, either use an ungreedy repeat such as "a\ed+?" or set
  3944. the PCRE2_NO_AUTO_POSSESS option when compiling.
  3945. .
  3946. .
  3947. .SS "Error returns from \fBpcre2_dfa_match()\fP"
  3948. .rs
  3949. .sp
  3950. The \fBpcre2_dfa_match()\fP function returns a negative number when it fails.
  3951. Many of the errors are the same as for \fBpcre2_match()\fP, as described
  3952. .\" HTML <a href="#errorlist">
  3953. .\" </a>
  3954. above.
  3955. .\"
  3956. There are in addition the following errors that are specific to
  3957. \fBpcre2_dfa_match()\fP:
  3958. .sp
  3959. PCRE2_ERROR_DFA_UITEM
  3960. .sp
  3961. This return is given if \fBpcre2_dfa_match()\fP encounters an item in the
  3962. pattern that it does not support, for instance, the use of \eC in a UTF mode or
  3963. a backreference.
  3964. .sp
  3965. PCRE2_ERROR_DFA_UCOND
  3966. .sp
  3967. This return is given if \fBpcre2_dfa_match()\fP encounters a condition item
  3968. that uses a backreference for the condition, or a test for recursion in a
  3969. specific capture group. These are not supported.
  3970. .sp
  3971. PCRE2_ERROR_DFA_UINVALID_UTF
  3972. .sp
  3973. This return is given if \fBpcre2_dfa_match()\fP is called for a pattern that
  3974. was compiled with PCRE2_MATCH_INVALID_UTF. This is not supported for DFA
  3975. matching.
  3976. .sp
  3977. PCRE2_ERROR_DFA_WSSIZE
  3978. .sp
  3979. This return is given if \fBpcre2_dfa_match()\fP runs out of space in the
  3980. \fIworkspace\fP vector.
  3981. .sp
  3982. PCRE2_ERROR_DFA_RECURSE
  3983. .sp
  3984. When a recursion or subroutine call is processed, the matching function calls
  3985. itself recursively, using private memory for the ovector and \fIworkspace\fP.
  3986. This error is given if the internal ovector is not large enough. This should be
  3987. extremely rare, as a vector of size 1000 is used.
  3988. .sp
  3989. PCRE2_ERROR_DFA_BADRESTART
  3990. .sp
  3991. When \fBpcre2_dfa_match()\fP is called with the \fBPCRE2_DFA_RESTART\fP option,
  3992. some plausibility checks are made on the contents of the workspace, which
  3993. should contain data about the previous partial match. If any of these checks
  3994. fail, this error is given.
  3995. .
  3996. .
  3997. .SH "SEE ALSO"
  3998. .rs
  3999. .sp
  4000. \fBpcre2build\fP(3), \fBpcre2callout\fP(3), \fBpcre2demo(3)\fP,
  4001. \fBpcre2matching\fP(3), \fBpcre2partial\fP(3), \fBpcre2posix\fP(3),
  4002. \fBpcre2sample\fP(3), \fBpcre2unicode\fP(3).
  4003. .
  4004. .
  4005. .SH AUTHOR
  4006. .rs
  4007. .sp
  4008. .nf
  4009. Philip Hazel
  4010. Retired from University Computing Service
  4011. Cambridge, England.
  4012. .fi
  4013. .
  4014. .
  4015. .SH REVISION
  4016. .rs
  4017. .sp
  4018. .nf
  4019. Last updated: 30 August 2021
  4020. Copyright (c) 1997-2021 University of Cambridge.
  4021. .fi