pcre2api.3 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005
  1. .TH PCRE2API 3 "04 November 2020" "PCRE2 10.36"
  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_SURROGATE_ESCAPES
  1880. .sp
  1881. This option applies when compiling a pattern in UTF-8 or UTF-32 mode. It is
  1882. forbidden in UTF-16 mode, and ignored in non-UTF modes. Unicode "surrogate"
  1883. code points in the range 0xd800 to 0xdfff are used in pairs in UTF-16 to encode
  1884. code points with values in the range 0x10000 to 0x10ffff. The surrogates cannot
  1885. therefore be represented in UTF-16. They can be represented in UTF-8 and
  1886. UTF-32, but are defined as invalid code points, and cause errors if encountered
  1887. in a UTF-8 or UTF-32 string that is being checked for validity by PCRE2.
  1888. .P
  1889. These values also cause errors if encountered in escape sequences such as
  1890. \ex{d912} within a pattern. However, it seems that some applications, when
  1891. using PCRE2 to check for unwanted characters in UTF-8 strings, explicitly test
  1892. for the surrogates using escape sequences. The PCRE2_NO_UTF_CHECK option does
  1893. not disable the error that occurs, because it applies only to the testing of
  1894. input strings for UTF validity.
  1895. .P
  1896. If the extra option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is set, surrogate code
  1897. point values in UTF-8 and UTF-32 patterns no longer provoke errors and are
  1898. incorporated in the compiled pattern. However, they can only match subject
  1899. characters if the matching function is called with PCRE2_NO_UTF_CHECK set.
  1900. .sp
  1901. PCRE2_EXTRA_ALT_BSUX
  1902. .sp
  1903. The original option PCRE2_ALT_BSUX causes PCRE2 to process \eU, \eu, and \ex in
  1904. the way that ECMAscript (aka JavaScript) does. Additional functionality was
  1905. defined by ECMAscript 6; setting PCRE2_EXTRA_ALT_BSUX has the effect of
  1906. PCRE2_ALT_BSUX, but in addition it recognizes \eu{hhh..} as a hexadecimal
  1907. character code, where hhh.. is any number of hexadecimal digits.
  1908. .sp
  1909. PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL
  1910. .sp
  1911. This is a dangerous option. Use with care. By default, an unrecognized escape
  1912. such as \ej or a malformed one such as \ex{2z} causes a compile-time error when
  1913. detected by \fBpcre2_compile()\fP. Perl is somewhat inconsistent in handling
  1914. such items: for example, \ej is treated as a literal "j", and non-hexadecimal
  1915. digits in \ex{} are just ignored, though warnings are given in both cases if
  1916. Perl's warning switch is enabled. However, a malformed octal number after \eo{
  1917. always causes an error in Perl.
  1918. .P
  1919. If the PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL extra option is passed to
  1920. \fBpcre2_compile()\fP, all unrecognized or malformed escape sequences are
  1921. treated as single-character escapes. For example, \ej is a literal "j" and
  1922. \ex{2z} is treated as the literal string "x{2z}". Setting this option means
  1923. that typos in patterns may go undetected and have unexpected results. Also note
  1924. that a sequence such as [\eN{] is interpreted as a malformed attempt at
  1925. [\eN{...}] and so is treated as [N{] whereas [\eN] gives an error because an
  1926. unqualified \eN is a valid escape sequence but is not supported in a character
  1927. class. To reiterate: this is a dangerous option. Use with great care.
  1928. .sp
  1929. PCRE2_EXTRA_ESCAPED_CR_IS_LF
  1930. .sp
  1931. There are some legacy applications where the escape sequence \er in a pattern
  1932. is expected to match a newline. If this option is set, \er in a pattern is
  1933. converted to \en so that it matches a LF (linefeed) instead of a CR (carriage
  1934. return) character. The option does not affect a literal CR in the pattern, nor
  1935. does it affect CR specified as an explicit code point such as \ex{0D}.
  1936. .sp
  1937. PCRE2_EXTRA_MATCH_LINE
  1938. .sp
  1939. This option is provided for use by the \fB-x\fP option of \fBpcre2grep\fP. It
  1940. causes the pattern only to match complete lines. This is achieved by
  1941. automatically inserting the code for "^(?:" at the start of the compiled
  1942. pattern and ")$" at the end. Thus, when PCRE2_MULTILINE is set, the matched
  1943. line may be in the middle of the subject string. This option can be used with
  1944. PCRE2_LITERAL.
  1945. .sp
  1946. PCRE2_EXTRA_MATCH_WORD
  1947. .sp
  1948. This option is provided for use by the \fB-w\fP option of \fBpcre2grep\fP. It
  1949. causes the pattern only to match strings that have a word boundary at the start
  1950. and the end. This is achieved by automatically inserting the code for "\eb(?:"
  1951. at the start of the compiled pattern and ")\eb" at the end. The option may be
  1952. used with PCRE2_LITERAL. However, it is ignored if PCRE2_EXTRA_MATCH_LINE is
  1953. also set.
  1954. .
  1955. .
  1956. .\" HTML <a name="jitcompiling"></a>
  1957. .SH "JUST-IN-TIME (JIT) COMPILATION"
  1958. .rs
  1959. .sp
  1960. .nf
  1961. .B int pcre2_jit_compile(pcre2_code *\fIcode\fP, uint32_t \fIoptions\fP);
  1962. .sp
  1963. .B int pcre2_jit_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  1964. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  1965. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  1966. .B " pcre2_match_context *\fImcontext\fP);"
  1967. .sp
  1968. .B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP);
  1969. .sp
  1970. .B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
  1971. .B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
  1972. .sp
  1973. .B void pcre2_jit_stack_assign(pcre2_match_context *\fImcontext\fP,
  1974. .B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);"
  1975. .sp
  1976. .B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP);
  1977. .fi
  1978. .P
  1979. These functions provide support for JIT compilation, which, if the just-in-time
  1980. compiler is available, further processes a compiled pattern into machine code
  1981. that executes much faster than the \fBpcre2_match()\fP interpretive matching
  1982. function. Full details are given in the
  1983. .\" HREF
  1984. \fBpcre2jit\fP
  1985. .\"
  1986. documentation.
  1987. .P
  1988. JIT compilation is a heavyweight optimization. It can take some time for
  1989. patterns to be analyzed, and for one-off matches and simple patterns the
  1990. benefit of faster execution might be offset by a much slower compilation time.
  1991. Most (but not all) patterns can be optimized by the JIT compiler.
  1992. .
  1993. .
  1994. .\" HTML <a name="localesupport"></a>
  1995. .SH "LOCALE SUPPORT"
  1996. .rs
  1997. .sp
  1998. .nf
  1999. .B const uint8_t *pcre2_maketables(pcre2_general_context *\fIgcontext\fP);
  2000. .sp
  2001. .B void pcre2_maketables_free(pcre2_general_context *\fIgcontext\fP,
  2002. .B " const uint8_t *\fItables\fP);"
  2003. .fi
  2004. .P
  2005. PCRE2 handles caseless matching, and determines whether characters are letters,
  2006. digits, or whatever, by reference to a set of tables, indexed by character code
  2007. point. However, this applies only to characters whose code points are less than
  2008. 256. By default, higher-valued code points never match escapes such as \ew or
  2009. \ed.
  2010. .P
  2011. When PCRE2 is built with Unicode support (the default), the Unicode properties
  2012. of all characters can be tested with \ep and \eP, or, alternatively, the
  2013. PCRE2_UCP option can be set when a pattern is compiled; this causes \ew and
  2014. friends to use Unicode property support instead of the built-in tables.
  2015. PCRE2_UCP also causes upper/lower casing operations on characters with code
  2016. points greater than 127 to use Unicode properties. These effects apply even
  2017. when PCRE2_UTF is not set.
  2018. .P
  2019. The use of locales with Unicode is discouraged. If you are handling characters
  2020. with code points greater than 127, you should either use Unicode support, or
  2021. use locales, but not try to mix the two.
  2022. .P
  2023. PCRE2 contains a built-in set of character tables that are used by default.
  2024. These are sufficient for many applications. Normally, the internal tables
  2025. recognize only ASCII characters. However, when PCRE2 is built, it is possible
  2026. to cause the internal tables to be rebuilt in the default "C" locale of the
  2027. local system, which may cause them to be different.
  2028. .P
  2029. The built-in tables can be overridden by tables supplied by the application
  2030. that calls PCRE2. These may be created in a different locale from the default.
  2031. As more and more applications change to using Unicode, the need for this locale
  2032. support is expected to die away.
  2033. .P
  2034. External tables are built by calling the \fBpcre2_maketables()\fP function, in
  2035. the relevant locale. The only argument to this function is a general context,
  2036. which can be used to pass a custom memory allocator. If the argument is NULL,
  2037. the system \fBmalloc()\fP is used. The result can be passed to
  2038. \fBpcre2_compile()\fP as often as necessary, by creating a compile context and
  2039. calling \fBpcre2_set_character_tables()\fP to set the tables pointer therein.
  2040. .P
  2041. For example, to build and use tables that are appropriate for the French locale
  2042. (where accented characters with values greater than 127 are treated as
  2043. letters), the following code could be used:
  2044. .sp
  2045. setlocale(LC_CTYPE, "fr_FR");
  2046. tables = pcre2_maketables(NULL);
  2047. ccontext = pcre2_compile_context_create(NULL);
  2048. pcre2_set_character_tables(ccontext, tables);
  2049. re = pcre2_compile(..., ccontext);
  2050. .sp
  2051. The locale name "fr_FR" is used on Linux and other Unix-like systems; if you
  2052. are using Windows, the name for the French locale is "french".
  2053. .P
  2054. The pointer that is passed (via the compile context) to \fBpcre2_compile()\fP
  2055. is saved with the compiled pattern, and the same tables are used by the
  2056. matching functions. Thus, for any single pattern, compilation and matching both
  2057. happen in the same locale, but different patterns can be processed in different
  2058. locales.
  2059. .P
  2060. It is the caller's responsibility to ensure that the memory containing the
  2061. tables remains available while they are still in use. When they are no longer
  2062. needed, you can discard them using \fBpcre2_maketables_free()\fP, which should
  2063. pass as its first parameter the same global context that was used to create the
  2064. tables.
  2065. .
  2066. .
  2067. .SS "Saving locale tables"
  2068. .rs
  2069. .sp
  2070. The tables described above are just a sequence of binary bytes, which makes
  2071. them independent of hardware characteristics such as endianness or whether the
  2072. processor is 32-bit or 64-bit. A copy of the result of \fBpcre2_maketables()\fP
  2073. can therefore be saved in a file or elsewhere and re-used later, even in a
  2074. different program or on another computer. The size of the tables (number of
  2075. bytes) must be obtained by calling \fBpcre2_config()\fP with the
  2076. PCRE2_CONFIG_TABLES_LENGTH option because \fBpcre2_maketables()\fP does not
  2077. return this value. Note that the \fBpcre2_dftables\fP program, which is part of
  2078. the PCRE2 build system, can be used stand-alone to create a file that contains
  2079. a set of binary tables. See the
  2080. .\" HTML <a href="pcre2build.html#createtables">
  2081. .\" </a>
  2082. \fBpcre2build\fP
  2083. .\"
  2084. documentation for details.
  2085. .
  2086. .
  2087. .\" HTML <a name="infoaboutpattern"></a>
  2088. .SH "INFORMATION ABOUT A COMPILED PATTERN"
  2089. .rs
  2090. .sp
  2091. .nf
  2092. .B int pcre2_pattern_info(const pcre2 *\fIcode\fP, uint32_t \fIwhat\fP, void *\fIwhere\fP);
  2093. .fi
  2094. .P
  2095. The \fBpcre2_pattern_info()\fP function returns general information about a
  2096. compiled pattern. For information about callouts, see the
  2097. .\" HTML <a href="#infoaboutcallouts">
  2098. .\" </a>
  2099. next section.
  2100. .\"
  2101. The first argument for \fBpcre2_pattern_info()\fP is a pointer to the compiled
  2102. pattern. The second argument specifies which piece of information is required,
  2103. and the third argument is a pointer to a variable to receive the data. If the
  2104. third argument is NULL, the first argument is ignored, and the function returns
  2105. the size in bytes of the variable that is required for the information
  2106. requested. Otherwise, the yield of the function is zero for success, or one of
  2107. the following negative numbers:
  2108. .sp
  2109. PCRE2_ERROR_NULL the argument \fIcode\fP was NULL
  2110. PCRE2_ERROR_BADMAGIC the "magic number" was not found
  2111. PCRE2_ERROR_BADOPTION the value of \fIwhat\fP was invalid
  2112. PCRE2_ERROR_UNSET the requested field is not set
  2113. .sp
  2114. The "magic number" is placed at the start of each compiled pattern as a simple
  2115. check against passing an arbitrary memory pointer. Here is a typical call of
  2116. \fBpcre2_pattern_info()\fP, to obtain the length of the compiled pattern:
  2117. .sp
  2118. int rc;
  2119. size_t length;
  2120. rc = pcre2_pattern_info(
  2121. re, /* result of pcre2_compile() */
  2122. PCRE2_INFO_SIZE, /* what is required */
  2123. &length); /* where to put the data */
  2124. .sp
  2125. The possible values for the second argument are defined in \fBpcre2.h\fP, and
  2126. are as follows:
  2127. .sp
  2128. PCRE2_INFO_ALLOPTIONS
  2129. PCRE2_INFO_ARGOPTIONS
  2130. PCRE2_INFO_EXTRAOPTIONS
  2131. .sp
  2132. Return copies of the pattern's options. The third argument should point to a
  2133. \fBuint32_t\fP variable. PCRE2_INFO_ARGOPTIONS returns exactly the options that
  2134. were passed to \fBpcre2_compile()\fP, whereas PCRE2_INFO_ALLOPTIONS returns
  2135. the compile options as modified by any top-level (*XXX) option settings such as
  2136. (*UTF) at the start of the pattern itself. PCRE2_INFO_EXTRAOPTIONS returns the
  2137. extra options that were set in the compile context by calling the
  2138. pcre2_set_compile_extra_options() function.
  2139. .P
  2140. For example, if the pattern /(*UTF)abc/ is compiled with the PCRE2_EXTENDED
  2141. option, the result for PCRE2_INFO_ALLOPTIONS is PCRE2_EXTENDED and PCRE2_UTF.
  2142. Option settings such as (?i) that can change within a pattern do not affect the
  2143. result of PCRE2_INFO_ALLOPTIONS, even if they appear right at the start of the
  2144. pattern. (This was different in some earlier releases.)
  2145. .P
  2146. A pattern compiled without PCRE2_ANCHORED is automatically anchored by PCRE2 if
  2147. the first significant item in every top-level branch is one of the following:
  2148. .sp
  2149. ^ unless PCRE2_MULTILINE is set
  2150. \eA always
  2151. \eG always
  2152. .* sometimes - see below
  2153. .sp
  2154. When .* is the first significant item, anchoring is possible only when all the
  2155. following are true:
  2156. .sp
  2157. .* is not in an atomic group
  2158. .\" JOIN
  2159. .* is not in a capture group that is the subject
  2160. of a backreference
  2161. PCRE2_DOTALL is in force for .*
  2162. Neither (*PRUNE) nor (*SKIP) appears in the pattern
  2163. PCRE2_NO_DOTSTAR_ANCHOR is not set
  2164. .sp
  2165. For patterns that are auto-anchored, the PCRE2_ANCHORED bit is set in the
  2166. options returned for PCRE2_INFO_ALLOPTIONS.
  2167. .sp
  2168. PCRE2_INFO_BACKREFMAX
  2169. .sp
  2170. Return the number of the highest backreference in the pattern. The third
  2171. argument should point to a \fBuint32_t\fP variable. Named capture groups
  2172. acquire numbers as well as names, and these count towards the highest
  2173. backreference. Backreferences such as \e4 or \eg{12} match the captured
  2174. characters of the given group, but in addition, the check that a capture
  2175. group is set in a conditional group such as (?(3)a|b) is also a backreference.
  2176. Zero is returned if there are no backreferences.
  2177. .sp
  2178. PCRE2_INFO_BSR
  2179. .sp
  2180. The output is a uint32_t integer whose value indicates what character sequences
  2181. the \eR escape sequence matches. A value of PCRE2_BSR_UNICODE means that \eR
  2182. matches any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means
  2183. that \eR matches only CR, LF, or CRLF.
  2184. .sp
  2185. PCRE2_INFO_CAPTURECOUNT
  2186. .sp
  2187. Return the highest capture group number in the pattern. In patterns where (?|
  2188. is not used, this is also the total number of capture groups. The third
  2189. argument should point to a \fBuint32_t\fP variable.
  2190. .sp
  2191. PCRE2_INFO_DEPTHLIMIT
  2192. .sp
  2193. If the pattern set a backtracking depth limit by including an item of the form
  2194. (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The third argument
  2195. should point to a uint32_t integer. If no such value has been set, the call to
  2196. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2197. limit will only be used during matching if it is less than the limit set or
  2198. defaulted by the caller of the match function.
  2199. .sp
  2200. PCRE2_INFO_FIRSTBITMAP
  2201. .sp
  2202. In the absence of a single first code unit for a non-anchored pattern,
  2203. \fBpcre2_compile()\fP may construct a 256-bit table that defines a fixed set of
  2204. values for the first code unit in any match. For example, a pattern that starts
  2205. with [abc] results in a table with three bits set. When code unit values
  2206. greater than 255 are supported, the flag bit for 255 means "any code unit of
  2207. value 255 or above". If such a table was constructed, a pointer to it is
  2208. returned. Otherwise NULL is returned. The third argument should point to a
  2209. \fBconst uint8_t *\fP variable.
  2210. .sp
  2211. PCRE2_INFO_FIRSTCODETYPE
  2212. .sp
  2213. Return information about the first code unit of any matched string, for a
  2214. non-anchored pattern. The third argument should point to a \fBuint32_t\fP
  2215. variable. If there is a fixed first value, for example, the letter "c" from a
  2216. pattern such as (cat|cow|coyote), 1 is returned, and the value can be retrieved
  2217. using PCRE2_INFO_FIRSTCODEUNIT. If there is no fixed first value, but it is
  2218. known that a match can occur only at the start of the subject or following a
  2219. newline in the subject, 2 is returned. Otherwise, and for anchored patterns, 0
  2220. is returned.
  2221. .sp
  2222. PCRE2_INFO_FIRSTCODEUNIT
  2223. .sp
  2224. Return the value of the first code unit of any matched string for a pattern
  2225. where PCRE2_INFO_FIRSTCODETYPE returns 1; otherwise return 0. The third
  2226. argument should point to a \fBuint32_t\fP variable. In the 8-bit library, the
  2227. value is always less than 256. In the 16-bit library the value can be up to
  2228. 0xffff. In the 32-bit library in UTF-32 mode the value can be up to 0x10ffff,
  2229. and up to 0xffffffff when not using UTF-32 mode.
  2230. .sp
  2231. PCRE2_INFO_FRAMESIZE
  2232. .sp
  2233. Return the size (in bytes) of the data frames that are used to remember
  2234. backtracking positions when the pattern is processed by \fBpcre2_match()\fP
  2235. without the use of JIT. The third argument should point to a \fBsize_t\fP
  2236. variable. The frame size depends on the number of capturing parentheses in the
  2237. pattern. Each additional capture group adds two PCRE2_SIZE variables.
  2238. .sp
  2239. PCRE2_INFO_HASBACKSLASHC
  2240. .sp
  2241. Return 1 if the pattern contains any instances of \eC, otherwise 0. The third
  2242. argument should point to a \fBuint32_t\fP variable.
  2243. .sp
  2244. PCRE2_INFO_HASCRORLF
  2245. .sp
  2246. Return 1 if the pattern contains any explicit matches for CR or LF characters,
  2247. otherwise 0. The third argument should point to a \fBuint32_t\fP variable. An
  2248. explicit match is either a literal CR or LF character, or \er or \en or one of
  2249. the equivalent hexadecimal or octal escape sequences.
  2250. .sp
  2251. PCRE2_INFO_HEAPLIMIT
  2252. .sp
  2253. If the pattern set a heap memory limit by including an item of the form
  2254. (*LIMIT_HEAP=nnnn) at the start, the value is returned. The third argument
  2255. should point to a uint32_t integer. If no such value has been set, the call to
  2256. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2257. limit will only be used during matching if it is less than the limit set or
  2258. defaulted by the caller of the match function.
  2259. .sp
  2260. PCRE2_INFO_JCHANGED
  2261. .sp
  2262. Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise
  2263. 0. The third argument should point to a \fBuint32_t\fP variable. (?J) and
  2264. (?-J) set and unset the local PCRE2_DUPNAMES option, respectively.
  2265. .sp
  2266. PCRE2_INFO_JITSIZE
  2267. .sp
  2268. If the compiled pattern was successfully processed by
  2269. \fBpcre2_jit_compile()\fP, return the size of the JIT compiled code, otherwise
  2270. return zero. The third argument should point to a \fBsize_t\fP variable.
  2271. .sp
  2272. PCRE2_INFO_LASTCODETYPE
  2273. .sp
  2274. Returns 1 if there is a rightmost literal code unit that must exist in any
  2275. matched string, other than at its start. The third argument should point to a
  2276. \fBuint32_t\fP variable. If there is no such value, 0 is returned. When 1 is
  2277. returned, the code unit value itself can be retrieved using
  2278. PCRE2_INFO_LASTCODEUNIT. For anchored patterns, a last literal value is
  2279. recorded only if it follows something of variable length. For example, for the
  2280. pattern /^a\ed+z\ed+/ the returned value is 1 (with "z" returned from
  2281. PCRE2_INFO_LASTCODEUNIT), but for /^a\edz\ed/ the returned value is 0.
  2282. .sp
  2283. PCRE2_INFO_LASTCODEUNIT
  2284. .sp
  2285. Return the value of the rightmost literal code unit that must exist in any
  2286. matched string, other than at its start, for a pattern where
  2287. PCRE2_INFO_LASTCODETYPE returns 1. Otherwise, return 0. The third argument
  2288. should point to a \fBuint32_t\fP variable.
  2289. .sp
  2290. PCRE2_INFO_MATCHEMPTY
  2291. .sp
  2292. Return 1 if the pattern might match an empty string, otherwise 0. The third
  2293. argument should point to a \fBuint32_t\fP variable. When a pattern contains
  2294. recursive subroutine calls it is not always possible to determine whether or
  2295. not it can match an empty string. PCRE2 takes a cautious approach and returns 1
  2296. in such cases.
  2297. .sp
  2298. PCRE2_INFO_MATCHLIMIT
  2299. .sp
  2300. If the pattern set a match limit by including an item of the form
  2301. (*LIMIT_MATCH=nnnn) at the start, the value is returned. The third argument
  2302. should point to a uint32_t integer. If no such value has been set, the call to
  2303. \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this
  2304. limit will only be used during matching if it is less than the limit set or
  2305. defaulted by the caller of the match function.
  2306. .sp
  2307. PCRE2_INFO_MAXLOOKBEHIND
  2308. .sp
  2309. A lookbehind assertion moves back a certain number of characters (not code
  2310. units) when it starts to process each of its branches. This request returns the
  2311. largest of these backward moves. The third argument should point to a uint32_t
  2312. integer. The simple assertions \eb and \eB require a one-character lookbehind
  2313. and cause PCRE2_INFO_MAXLOOKBEHIND to return 1 in the absence of anything
  2314. longer. \eA also registers a one-character lookbehind, though it does not
  2315. actually inspect the previous character.
  2316. .P
  2317. Note that this information is useful for multi-segment matching only
  2318. if the pattern contains no nested lookbehinds. For example, the pattern
  2319. (?<=a(?<=ba)c) returns a maximum lookbehind of 2, but when it is processed, the
  2320. first lookbehind moves back by two characters, matches one character, then the
  2321. nested lookbehind also moves back by two characters. This puts the matching
  2322. point three characters earlier than it was at the start.
  2323. PCRE2_INFO_MAXLOOKBEHIND is really only useful as a debugging tool. See the
  2324. .\" HREF
  2325. \fBpcre2partial\fP
  2326. .\"
  2327. documentation for a discussion of multi-segment matching.
  2328. .sp
  2329. PCRE2_INFO_MINLENGTH
  2330. .sp
  2331. If a minimum length for matching subject strings was computed, its value is
  2332. returned. Otherwise the returned value is 0. This value is not computed when
  2333. PCRE2_NO_START_OPTIMIZE is set. The value is a number of characters, which in
  2334. UTF mode may be different from the number of code units. The third argument
  2335. should point to a \fBuint32_t\fP variable. The value is a lower bound to the
  2336. length of any matching string. There may not be any strings of that length that
  2337. do actually match, but every string that does match is at least that long.
  2338. .sp
  2339. PCRE2_INFO_NAMECOUNT
  2340. PCRE2_INFO_NAMEENTRYSIZE
  2341. PCRE2_INFO_NAMETABLE
  2342. .sp
  2343. PCRE2 supports the use of named as well as numbered capturing parentheses. The
  2344. names are just an additional way of identifying the parentheses, which still
  2345. acquire numbers. Several convenience functions such as
  2346. \fBpcre2_substring_get_byname()\fP are provided for extracting captured
  2347. substrings by name. It is also possible to extract the data directly, by first
  2348. converting the name to a number in order to access the correct pointers in the
  2349. output vector (described with \fBpcre2_match()\fP below). To do the conversion,
  2350. you need to use the name-to-number map, which is described by these three
  2351. values.
  2352. .P
  2353. The map consists of a number of fixed-size entries. PCRE2_INFO_NAMECOUNT gives
  2354. the number of entries, and PCRE2_INFO_NAMEENTRYSIZE gives the size of each
  2355. entry in code units; both of these return a \fBuint32_t\fP value. The entry
  2356. size depends on the length of the longest name.
  2357. .P
  2358. PCRE2_INFO_NAMETABLE returns a pointer to the first entry of the table. This is
  2359. a PCRE2_SPTR pointer to a block of code units. In the 8-bit library, the first
  2360. two bytes of each entry are the number of the capturing parenthesis, most
  2361. significant byte first. In the 16-bit library, the pointer points to 16-bit
  2362. code units, the first of which contains the parenthesis number. In the 32-bit
  2363. library, the pointer points to 32-bit code units, the first of which contains
  2364. the parenthesis number. The rest of the entry is the corresponding name, zero
  2365. terminated.
  2366. .P
  2367. The names are in alphabetical order. If (?| is used to create multiple capture
  2368. groups with the same number, as described in the
  2369. .\" HTML <a href="pcre2pattern.html#dupgroupnumber">
  2370. .\" </a>
  2371. section on duplicate group numbers
  2372. .\"
  2373. in the
  2374. .\" HREF
  2375. \fBpcre2pattern\fP
  2376. .\"
  2377. page, the groups may be given the same name, but there is only one entry in the
  2378. table. Different names for groups of the same number are not permitted.
  2379. .P
  2380. Duplicate names for capture groups with different numbers are permitted, but
  2381. only if PCRE2_DUPNAMES is set. They appear in the table in the order in which
  2382. they were found in the pattern. In the absence of (?| this is the order of
  2383. increasing number; when (?| is used this is not necessarily the case because
  2384. later capture groups may have lower numbers.
  2385. .P
  2386. As a simple example of the name/number table, consider the following pattern
  2387. after compilation by the 8-bit library (assume PCRE2_EXTENDED is set, so white
  2388. space - including newlines - is ignored):
  2389. .sp
  2390. .\" JOIN
  2391. (?<date> (?<year>(\ed\ed)?\ed\ed) -
  2392. (?<month>\ed\ed) - (?<day>\ed\ed) )
  2393. .sp
  2394. There are four named capture groups, so the table has four entries, and each
  2395. entry in the table is eight bytes long. The table is as follows, with
  2396. non-printing bytes shows in hexadecimal, and undefined bytes shown as ??:
  2397. .sp
  2398. 00 01 d a t e 00 ??
  2399. 00 05 d a y 00 ?? ??
  2400. 00 04 m o n t h 00
  2401. 00 02 y e a r 00 ??
  2402. .sp
  2403. When writing code to extract data from named capture groups using the
  2404. name-to-number map, remember that the length of the entries is likely to be
  2405. different for each compiled pattern.
  2406. .sp
  2407. PCRE2_INFO_NEWLINE
  2408. .sp
  2409. The output is one of the following \fBuint32_t\fP values:
  2410. .sp
  2411. PCRE2_NEWLINE_CR Carriage return (CR)
  2412. PCRE2_NEWLINE_LF Linefeed (LF)
  2413. PCRE2_NEWLINE_CRLF Carriage return, linefeed (CRLF)
  2414. PCRE2_NEWLINE_ANY Any Unicode line ending
  2415. PCRE2_NEWLINE_ANYCRLF Any of CR, LF, or CRLF
  2416. PCRE2_NEWLINE_NUL The NUL character (binary zero)
  2417. .sp
  2418. This identifies the character sequence that will be recognized as meaning
  2419. "newline" while matching.
  2420. .sp
  2421. PCRE2_INFO_SIZE
  2422. .sp
  2423. Return the size of the compiled pattern in bytes (for all three libraries). The
  2424. third argument should point to a \fBsize_t\fP variable. This value includes the
  2425. size of the general data block that precedes the code units of the compiled
  2426. pattern itself. The value that is used when \fBpcre2_compile()\fP is getting
  2427. memory in which to place the compiled pattern may be slightly larger than the
  2428. value returned by this option, because there are cases where the code that
  2429. calculates the size has to over-estimate. Processing a pattern with the JIT
  2430. compiler does not alter the value returned by this option.
  2431. .
  2432. .
  2433. .\" HTML <a name="infoaboutcallouts"></a>
  2434. .SH "INFORMATION ABOUT A PATTERN'S CALLOUTS"
  2435. .rs
  2436. .sp
  2437. .nf
  2438. .B int pcre2_callout_enumerate(const pcre2_code *\fIcode\fP,
  2439. .B " int (*\fIcallback\fP)(pcre2_callout_enumerate_block *, void *),"
  2440. .B " void *\fIuser_data\fP);"
  2441. .fi
  2442. .sp
  2443. A script language that supports the use of string arguments in callouts might
  2444. like to scan all the callouts in a pattern before running the match. This can
  2445. be done by calling \fBpcre2_callout_enumerate()\fP. The first argument is a
  2446. pointer to a compiled pattern, the second points to a callback function, and
  2447. the third is arbitrary user data. The callback function is called for every
  2448. callout in the pattern in the order in which they appear. Its first argument is
  2449. a pointer to a callout enumeration block, and its second argument is the
  2450. \fIuser_data\fP value that was passed to \fBpcre2_callout_enumerate()\fP. The
  2451. contents of the callout enumeration block are described in the
  2452. .\" HREF
  2453. \fBpcre2callout\fP
  2454. .\"
  2455. documentation, which also gives further details about callouts.
  2456. .
  2457. .
  2458. .SH "SERIALIZATION AND PRECOMPILING"
  2459. .rs
  2460. .sp
  2461. It is possible to save compiled patterns on disc or elsewhere, and reload them
  2462. later, subject to a number of restrictions. The host on which the patterns are
  2463. reloaded must be running the same version of PCRE2, with the same code unit
  2464. width, and must also have the same endianness, pointer width, and PCRE2_SIZE
  2465. type. Before compiled patterns can be saved, they must be converted to a
  2466. "serialized" form, which in the case of PCRE2 is really just a bytecode dump.
  2467. The functions whose names begin with \fBpcre2_serialize_\fP are used for
  2468. converting to and from the serialized form. They are described in the
  2469. .\" HREF
  2470. \fBpcre2serialize\fP
  2471. .\"
  2472. documentation. Note that PCRE2 serialization does not convert compiled patterns
  2473. to an abstract format like Java or .NET serialization.
  2474. .
  2475. .
  2476. .\" HTML <a name="matchdatablock"></a>
  2477. .SH "THE MATCH DATA BLOCK"
  2478. .rs
  2479. .sp
  2480. .nf
  2481. .B pcre2_match_data *pcre2_match_data_create(uint32_t \fIovecsize\fP,
  2482. .B " pcre2_general_context *\fIgcontext\fP);"
  2483. .sp
  2484. .B pcre2_match_data *pcre2_match_data_create_from_pattern(
  2485. .B " const pcre2_code *\fIcode\fP, pcre2_general_context *\fIgcontext\fP);"
  2486. .sp
  2487. .B void pcre2_match_data_free(pcre2_match_data *\fImatch_data\fP);
  2488. .fi
  2489. .P
  2490. Information about a successful or unsuccessful match is placed in a match
  2491. data block, which is an opaque structure that is accessed by function calls. In
  2492. particular, the match data block contains a vector of offsets into the subject
  2493. string that define the matched part of the subject and any substrings that were
  2494. captured. This is known as the \fIovector\fP.
  2495. .P
  2496. Before calling \fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or
  2497. \fBpcre2_jit_match()\fP you must create a match data block by calling one of
  2498. the creation functions above. For \fBpcre2_match_data_create()\fP, the first
  2499. argument is the number of pairs of offsets in the \fIovector\fP. One pair of
  2500. offsets is required to identify the string that matched the whole pattern, with
  2501. an additional pair for each captured substring. For example, a value of 4
  2502. creates enough space to record the matched portion of the subject plus three
  2503. captured substrings. A minimum of at least 1 pair is imposed by
  2504. \fBpcre2_match_data_create()\fP, so it is always possible to return the overall
  2505. matched string.
  2506. .P
  2507. The second argument of \fBpcre2_match_data_create()\fP is a pointer to a
  2508. general context, which can specify custom memory management for obtaining the
  2509. memory for the match data block. If you are not using custom memory management,
  2510. pass NULL, which causes \fBmalloc()\fP to be used.
  2511. .P
  2512. For \fBpcre2_match_data_create_from_pattern()\fP, the first argument is a
  2513. pointer to a compiled pattern. The ovector is created to be exactly the right
  2514. size to hold all the substrings a pattern might capture. The second argument is
  2515. again a pointer to a general context, but in this case if NULL is passed, the
  2516. memory is obtained using the same allocator that was used for the compiled
  2517. pattern (custom or default).
  2518. .P
  2519. A match data block can be used many times, with the same or different compiled
  2520. patterns. You can extract information from a match data block after a match
  2521. operation has finished, using functions that are described in the sections on
  2522. .\" HTML <a href="#matchedstrings">
  2523. .\" </a>
  2524. matched strings
  2525. .\"
  2526. and
  2527. .\" HTML <a href="#matchotherdata">
  2528. .\" </a>
  2529. other match data
  2530. .\"
  2531. below.
  2532. .P
  2533. When a call of \fBpcre2_match()\fP fails, valid data is available in the match
  2534. block only when the error is PCRE2_ERROR_NOMATCH, PCRE2_ERROR_PARTIAL, or one
  2535. of the error codes for an invalid UTF string. Exactly what is available depends
  2536. on the error, and is detailed below.
  2537. .P
  2538. When one of the matching functions is called, pointers to the compiled pattern
  2539. and the subject string are set in the match data block so that they can be
  2540. referenced by the extraction functions after a successful match. After running
  2541. a match, you must not free a compiled pattern or a subject string until after
  2542. all operations on the match data block (for that match) have taken place,
  2543. unless, in the case of the subject string, you have used the
  2544. PCRE2_COPY_MATCHED_SUBJECT option, which is described in the section entitled
  2545. "Option bits for \fBpcre2_match()\fP"
  2546. .\" HTML <a href="#matchoptions>">
  2547. .\" </a>
  2548. below.
  2549. .\"
  2550. .P
  2551. When a match data block itself is no longer needed, it should be freed by
  2552. calling \fBpcre2_match_data_free()\fP. If this function is called with a NULL
  2553. argument, it returns immediately, without doing anything.
  2554. .
  2555. .
  2556. .SH "MATCHING A PATTERN: THE TRADITIONAL FUNCTION"
  2557. .rs
  2558. .sp
  2559. .nf
  2560. .B int pcre2_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  2561. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  2562. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  2563. .B " pcre2_match_context *\fImcontext\fP);"
  2564. .fi
  2565. .P
  2566. The function \fBpcre2_match()\fP is called to match a subject string against a
  2567. compiled pattern, which is passed in the \fIcode\fP argument. You can call
  2568. \fBpcre2_match()\fP with the same \fIcode\fP argument as many times as you
  2569. like, in order to find multiple matches in the subject string or to match
  2570. different subject strings with the same pattern.
  2571. .P
  2572. This function is the main matching facility of the library, and it operates in
  2573. a Perl-like manner. For specialist use there is also an alternative matching
  2574. function, which is described
  2575. .\" HTML <a href="#dfamatch">
  2576. .\" </a>
  2577. below
  2578. .\"
  2579. in the section about the \fBpcre2_dfa_match()\fP function.
  2580. .P
  2581. Here is an example of a simple call to \fBpcre2_match()\fP:
  2582. .sp
  2583. pcre2_match_data *md = pcre2_match_data_create(4, NULL);
  2584. int rc = pcre2_match(
  2585. re, /* result of pcre2_compile() */
  2586. "some string", /* the subject string */
  2587. 11, /* the length of the subject string */
  2588. 0, /* start at offset 0 in the subject */
  2589. 0, /* default options */
  2590. md, /* the match data block */
  2591. NULL); /* a match context; NULL means use defaults */
  2592. .sp
  2593. If the subject string is zero-terminated, the length can be given as
  2594. PCRE2_ZERO_TERMINATED. A match context must be provided if certain less common
  2595. matching parameters are to be changed. For details, see the section on
  2596. .\" HTML <a href="#matchcontext">
  2597. .\" </a>
  2598. the match context
  2599. .\"
  2600. above.
  2601. .
  2602. .
  2603. .SS "The string to be matched by \fBpcre2_match()\fP"
  2604. .rs
  2605. .sp
  2606. The subject string is passed to \fBpcre2_match()\fP as a pointer in
  2607. \fIsubject\fP, a length in \fIlength\fP, and a starting offset in
  2608. \fIstartoffset\fP. The length and offset are in code units, not characters.
  2609. That is, they are in bytes for the 8-bit library, 16-bit code units for the
  2610. 16-bit library, and 32-bit code units for the 32-bit library, whether or not
  2611. UTF processing is enabled.
  2612. .P
  2613. If \fIstartoffset\fP is greater than the length of the subject,
  2614. \fBpcre2_match()\fP returns PCRE2_ERROR_BADOFFSET. When the starting offset is
  2615. zero, the search for a match starts at the beginning of the subject, and this
  2616. is by far the most common case. In UTF-8 or UTF-16 mode, the starting offset
  2617. must point to the start of a character, or to the end of the subject (in UTF-32
  2618. mode, one code unit equals one character, so all offsets are valid). Like the
  2619. pattern string, the subject may contain binary zeros.
  2620. .P
  2621. A non-zero starting offset is useful when searching for another match in the
  2622. same subject by calling \fBpcre2_match()\fP again after a previous success.
  2623. Setting \fIstartoffset\fP differs from passing over a shortened string and
  2624. setting PCRE2_NOTBOL in the case of a pattern that begins with any kind of
  2625. lookbehind. For example, consider the pattern
  2626. .sp
  2627. \eBiss\eB
  2628. .sp
  2629. which finds occurrences of "iss" in the middle of words. (\eB matches only if
  2630. the current position in the subject is not a word boundary.) When applied to
  2631. the string "Mississipi" the first call to \fBpcre2_match()\fP finds the first
  2632. occurrence. If \fBpcre2_match()\fP is called again with just the remainder of
  2633. the subject, namely "issipi", it does not match, because \eB is always false at
  2634. the start of the subject, which is deemed to be a word boundary. However, if
  2635. \fBpcre2_match()\fP is passed the entire string again, but with
  2636. \fIstartoffset\fP set to 4, it finds the second occurrence of "iss" because it
  2637. is able to look behind the starting point to discover that it is preceded by a
  2638. letter.
  2639. .P
  2640. Finding all the matches in a subject is tricky when the pattern can match an
  2641. empty string. It is possible to emulate Perl's /g behaviour by first trying the
  2642. match again at the same offset, with the PCRE2_NOTEMPTY_ATSTART and
  2643. PCRE2_ANCHORED options, and then if that fails, advancing the starting offset
  2644. and trying an ordinary match again. There is some code that demonstrates how to
  2645. do this in the
  2646. .\" HREF
  2647. \fBpcre2demo\fP
  2648. .\"
  2649. sample program. In the most general case, you have to check to see if the
  2650. newline convention recognizes CRLF as a newline, and if so, and the current
  2651. character is CR followed by LF, advance the starting offset by two characters
  2652. instead of one.
  2653. .P
  2654. If a non-zero starting offset is passed when the pattern is anchored, a single
  2655. attempt to match at the given offset is made. This can only succeed if the
  2656. pattern does not require the match to be at the start of the subject. In other
  2657. words, the anchoring must be the result of setting the PCRE2_ANCHORED option or
  2658. the use of .* with PCRE2_DOTALL, not by starting the pattern with ^ or \eA.
  2659. .
  2660. .
  2661. .\" HTML <a name="matchoptions"></a>
  2662. .SS "Option bits for \fBpcre2_match()\fP"
  2663. .rs
  2664. .sp
  2665. The unused bits of the \fIoptions\fP argument for \fBpcre2_match()\fP must be
  2666. zero. The only bits that may be set are PCRE2_ANCHORED,
  2667. PCRE2_COPY_MATCHED_SUBJECT, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL,
  2668. PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_JIT, PCRE2_NO_UTF_CHECK,
  2669. PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. Their action is described below.
  2670. .P
  2671. Setting PCRE2_ANCHORED or PCRE2_ENDANCHORED at match time is not supported by
  2672. the just-in-time (JIT) compiler. If it is set, JIT matching is disabled and the
  2673. interpretive code in \fBpcre2_match()\fP is run. Apart from PCRE2_NO_JIT
  2674. (obviously), the remaining options are supported for JIT matching.
  2675. .sp
  2676. PCRE2_ANCHORED
  2677. .sp
  2678. The PCRE2_ANCHORED option limits \fBpcre2_match()\fP to matching at the first
  2679. matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out
  2680. to be anchored by virtue of its contents, it cannot be made unachored at
  2681. matching time. Note that setting the option at match time disables JIT
  2682. matching.
  2683. .sp
  2684. PCRE2_COPY_MATCHED_SUBJECT
  2685. .sp
  2686. By default, a pointer to the subject is remembered in the match data block so
  2687. that, after a successful match, it can be referenced by the substring
  2688. extraction functions. This means that the subject's memory must not be freed
  2689. until all such operations are complete. For some applications where the
  2690. lifetime of the subject string is not guaranteed, it may be necessary to make a
  2691. copy of the subject string, but it is wasteful to do this unless the match is
  2692. successful. After a successful match, if PCRE2_COPY_MATCHED_SUBJECT is set, the
  2693. subject is copied and the new pointer is remembered in the match data block
  2694. instead of the original subject pointer. The memory allocator that was used for
  2695. the match block itself is used. The copy is automatically freed when
  2696. \fBpcre2_match_data_free()\fP is called to free the match data block. It is also
  2697. automatically freed if the match data block is re-used for another match
  2698. operation.
  2699. .sp
  2700. PCRE2_ENDANCHORED
  2701. .sp
  2702. If the PCRE2_ENDANCHORED option is set, any string that \fBpcre2_match()\fP
  2703. matches must be right at the end of the subject string. Note that setting the
  2704. option at match time disables JIT matching.
  2705. .sp
  2706. PCRE2_NOTBOL
  2707. .sp
  2708. This option specifies that first character of the subject string is not the
  2709. beginning of a line, so the circumflex metacharacter should not match before
  2710. it. Setting this without having set PCRE2_MULTILINE at compile time causes
  2711. circumflex never to match. This option affects only the behaviour of the
  2712. circumflex metacharacter. It does not affect \eA.
  2713. .sp
  2714. PCRE2_NOTEOL
  2715. .sp
  2716. This option specifies that the end of the subject string is not the end of a
  2717. line, so the dollar metacharacter should not match it nor (except in multiline
  2718. mode) a newline immediately before it. Setting this without having set
  2719. PCRE2_MULTILINE at compile time causes dollar never to match. This option
  2720. affects only the behaviour of the dollar metacharacter. It does not affect \eZ
  2721. or \ez.
  2722. .sp
  2723. PCRE2_NOTEMPTY
  2724. .sp
  2725. An empty string is not considered to be a valid match if this option is set. If
  2726. there are alternatives in the pattern, they are tried. If all the alternatives
  2727. match the empty string, the entire match fails. For example, if the pattern
  2728. .sp
  2729. a?b?
  2730. .sp
  2731. is applied to a string not beginning with "a" or "b", it matches an empty
  2732. string at the start of the subject. With PCRE2_NOTEMPTY set, this match is not
  2733. valid, so \fBpcre2_match()\fP searches further into the string for occurrences
  2734. of "a" or "b".
  2735. .sp
  2736. PCRE2_NOTEMPTY_ATSTART
  2737. .sp
  2738. This is like PCRE2_NOTEMPTY, except that it locks out an empty string match
  2739. only at the first matching position, that is, at the start of the subject plus
  2740. the starting offset. An empty string match later in the subject is permitted.
  2741. If the pattern is anchored, such a match can occur only if the pattern contains
  2742. \eK.
  2743. .sp
  2744. PCRE2_NO_JIT
  2745. .sp
  2746. By default, if a pattern has been successfully processed by
  2747. \fBpcre2_jit_compile()\fP, JIT is automatically used when \fBpcre2_match()\fP
  2748. is called with options that JIT supports. Setting PCRE2_NO_JIT disables the use
  2749. of JIT; it forces matching to be done by the interpreter.
  2750. .sp
  2751. PCRE2_NO_UTF_CHECK
  2752. .sp
  2753. When PCRE2_UTF is set at compile time, the validity of the subject as a UTF
  2754. string is checked unless PCRE2_NO_UTF_CHECK is passed to \fBpcre2_match()\fP or
  2755. PCRE2_MATCH_INVALID_UTF was passed to \fBpcre2_compile()\fP. The latter special
  2756. case is discussed in detail in the
  2757. .\" HREF
  2758. \fBpcre2unicode\fP
  2759. .\"
  2760. documentation.
  2761. .P
  2762. In the default case, if a non-zero starting offset is given, the check is
  2763. applied only to that part of the subject that could be inspected during
  2764. matching, and there is a check that the starting offset points to the first
  2765. code unit of a character or to the end of the subject. If there are no
  2766. lookbehind assertions in the pattern, the check starts at the starting offset.
  2767. Otherwise, it starts at the length of the longest lookbehind before the
  2768. starting offset, or at the start of the subject if there are not that many
  2769. characters before the starting offset. Note that the sequences \eb and \eB are
  2770. one-character lookbehinds.
  2771. .P
  2772. The check is carried out before any other processing takes place, and a
  2773. negative error code is returned if the check fails. There are several UTF error
  2774. codes for each code unit width, corresponding to different problems with the
  2775. code unit sequence. There are discussions about the validity of
  2776. .\" HTML <a href="pcre2unicode.html#utf8strings">
  2777. .\" </a>
  2778. UTF-8 strings,
  2779. .\"
  2780. .\" HTML <a href="pcre2unicode.html#utf16strings">
  2781. .\" </a>
  2782. UTF-16 strings,
  2783. .\"
  2784. and
  2785. .\" HTML <a href="pcre2unicode.html#utf32strings">
  2786. .\" </a>
  2787. UTF-32 strings
  2788. .\"
  2789. in the
  2790. .\" HREF
  2791. \fBpcre2unicode\fP
  2792. .\"
  2793. documentation.
  2794. .P
  2795. If you know that your subject is valid, and you want to skip this check for
  2796. performance reasons, you can set the PCRE2_NO_UTF_CHECK option when calling
  2797. \fBpcre2_match()\fP. You might want to do this for the second and subsequent
  2798. calls to \fBpcre2_match()\fP if you are making repeated calls to find multiple
  2799. matches in the same subject string.
  2800. .P
  2801. \fBWarning:\fP Unless PCRE2_MATCH_INVALID_UTF was set at compile time, when
  2802. PCRE2_NO_UTF_CHECK is set at match time the effect of passing an invalid
  2803. string as a subject, or an invalid value of \fIstartoffset\fP, is undefined.
  2804. Your program may crash or loop indefinitely or give wrong results.
  2805. .sp
  2806. PCRE2_PARTIAL_HARD
  2807. PCRE2_PARTIAL_SOFT
  2808. .sp
  2809. These options turn on the partial matching feature. A partial match occurs if
  2810. the end of the subject string is reached successfully, but there are not enough
  2811. subject characters to complete the match. In addition, either at least one
  2812. character must have been inspected or the pattern must contain a lookbehind, or
  2813. the pattern must be one that could match an empty string.
  2814. .P
  2815. If this situation arises when PCRE2_PARTIAL_SOFT (but not PCRE2_PARTIAL_HARD)
  2816. is set, matching continues by testing any remaining alternatives. Only if no
  2817. complete match can be found is PCRE2_ERROR_PARTIAL returned instead of
  2818. PCRE2_ERROR_NOMATCH. In other words, PCRE2_PARTIAL_SOFT specifies that the
  2819. caller is prepared to handle a partial match, but only if no complete match can
  2820. be found.
  2821. .P
  2822. If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this case, if
  2823. a partial match is found, \fBpcre2_match()\fP immediately returns
  2824. PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other
  2825. words, when PCRE2_PARTIAL_HARD is set, a partial match is considered to be more
  2826. important that an alternative complete match.
  2827. .P
  2828. There is a more detailed discussion of partial and multi-segment matching, with
  2829. examples, in the
  2830. .\" HREF
  2831. \fBpcre2partial\fP
  2832. .\"
  2833. documentation.
  2834. .
  2835. .
  2836. .
  2837. .SH "NEWLINE HANDLING WHEN MATCHING"
  2838. .rs
  2839. .sp
  2840. When PCRE2 is built, a default newline convention is set; this is usually the
  2841. standard convention for the operating system. The default can be overridden in
  2842. a
  2843. .\" HTML <a href="#compilecontext">
  2844. .\" </a>
  2845. compile context
  2846. .\"
  2847. by calling \fBpcre2_set_newline()\fP. It can also be overridden by starting a
  2848. pattern string with, for example, (*CRLF), as described in the
  2849. .\" HTML <a href="pcre2pattern.html#newlines">
  2850. .\" </a>
  2851. section on newline conventions
  2852. .\"
  2853. in the
  2854. .\" HREF
  2855. \fBpcre2pattern\fP
  2856. .\"
  2857. page. During matching, the newline choice affects the behaviour of the dot,
  2858. circumflex, and dollar metacharacters. It may also alter the way the match
  2859. starting position is advanced after a match failure for an unanchored pattern.
  2860. .P
  2861. When PCRE2_NEWLINE_CRLF, PCRE2_NEWLINE_ANYCRLF, or PCRE2_NEWLINE_ANY is set as
  2862. the newline convention, and a match attempt for an unanchored pattern fails
  2863. when the current starting position is at a CRLF sequence, and the pattern
  2864. contains no explicit matches for CR or LF characters, the match position is
  2865. advanced by two characters instead of one, in other words, to after the CRLF.
  2866. .P
  2867. The above rule is a compromise that makes the most common cases work as
  2868. expected. For example, if the pattern is .+A (and the PCRE2_DOTALL option is
  2869. not set), it does not match the string "\er\enA" because, after failing at the
  2870. start, it skips both the CR and the LF before retrying. However, the pattern
  2871. [\er\en]A does match that string, because it contains an explicit CR or LF
  2872. reference, and so advances only by one character after the first failure.
  2873. .P
  2874. An explicit match for CR of LF is either a literal appearance of one of those
  2875. characters in the pattern, or one of the \er or \en or equivalent octal or
  2876. hexadecimal escape sequences. Implicit matches such as [^X] do not count, nor
  2877. does \es, even though it includes CR and LF in the characters that it matches.
  2878. .P
  2879. Notwithstanding the above, anomalous effects may still occur when CRLF is a
  2880. valid newline sequence and explicit \er or \en escapes appear in the pattern.
  2881. .
  2882. .
  2883. .\" HTML <a name="matchedstrings"></a>
  2884. .SH "HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS"
  2885. .rs
  2886. .sp
  2887. .nf
  2888. .B uint32_t pcre2_get_ovector_count(pcre2_match_data *\fImatch_data\fP);
  2889. .sp
  2890. .B PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *\fImatch_data\fP);
  2891. .fi
  2892. .P
  2893. In general, a pattern matches a certain portion of the subject, and in
  2894. addition, further substrings from the subject may be picked out by
  2895. parenthesized parts of the pattern. Following the usage in Jeffrey Friedl's
  2896. book, this is called "capturing" in what follows, and the phrase "capture
  2897. group" (Perl terminology) is used for a fragment of a pattern that picks out a
  2898. substring. PCRE2 supports several other kinds of parenthesized group that do
  2899. not cause substrings to be captured. The \fBpcre2_pattern_info()\fP function
  2900. can be used to find out how many capture groups there are in a compiled
  2901. pattern.
  2902. .P
  2903. You can use auxiliary functions for accessing captured substrings
  2904. .\" HTML <a href="#extractbynumber">
  2905. .\" </a>
  2906. by number
  2907. .\"
  2908. or
  2909. .\" HTML <a href="#extractbyname">
  2910. .\" </a>
  2911. by name,
  2912. .\"
  2913. as described in sections below.
  2914. .P
  2915. Alternatively, you can make direct use of the vector of PCRE2_SIZE values,
  2916. called the \fBovector\fP, which contains the offsets of captured strings. It is
  2917. part of the
  2918. .\" HTML <a href="#matchdatablock">
  2919. .\" </a>
  2920. match data block.
  2921. .\"
  2922. The function \fBpcre2_get_ovector_pointer()\fP returns the address of the
  2923. ovector, and \fBpcre2_get_ovector_count()\fP returns the number of pairs of
  2924. values it contains.
  2925. .P
  2926. Within the ovector, the first in each pair of values is set to the offset of
  2927. the first code unit of a substring, and the second is set to the offset of the
  2928. first code unit after the end of a substring. These values are always code unit
  2929. offsets, not character offsets. That is, they are byte offsets in the 8-bit
  2930. library, 16-bit offsets in the 16-bit library, and 32-bit offsets in the 32-bit
  2931. library.
  2932. .P
  2933. After a partial match (error return PCRE2_ERROR_PARTIAL), only the first pair
  2934. of offsets (that is, \fIovector[0]\fP and \fIovector[1]\fP) are set. They
  2935. identify the part of the subject that was partially matched. See the
  2936. .\" HREF
  2937. \fBpcre2partial\fP
  2938. .\"
  2939. documentation for details of partial matching.
  2940. .P
  2941. After a fully successful match, the first pair of offsets identifies the
  2942. portion of the subject string that was matched by the entire pattern. The next
  2943. pair is used for the first captured substring, and so on. The value returned by
  2944. \fBpcre2_match()\fP is one more than the highest numbered pair that has been
  2945. set. For example, if two substrings have been captured, the returned value is
  2946. 3. If there are no captured substrings, the return value from a successful
  2947. match is 1, indicating that just the first pair of offsets has been set.
  2948. .P
  2949. If a pattern uses the \eK escape sequence within a positive assertion, the
  2950. reported start of a successful match can be greater than the end of the match.
  2951. For example, if the pattern (?=ab\eK) is matched against "ab", the start and
  2952. end offset values for the match are 2 and 0.
  2953. .P
  2954. If a capture group is matched repeatedly within a single match operation, it is
  2955. the last portion of the subject that it matched that is returned.
  2956. .P
  2957. If the ovector is too small to hold all the captured substring offsets, as much
  2958. as possible is filled in, and the function returns a value of zero. If captured
  2959. substrings are not of interest, \fBpcre2_match()\fP may be called with a match
  2960. data block whose ovector is of minimum length (that is, one pair).
  2961. .P
  2962. It is possible for capture group number \fIn+1\fP to match some part of the
  2963. subject when group \fIn\fP has not been used at all. For example, if the string
  2964. "abc" is matched against the pattern (a|(z))(bc) the return from the function
  2965. is 4, and groups 1 and 3 are matched, but 2 is not. When this happens, both
  2966. values in the offset pairs corresponding to unused groups are set to
  2967. PCRE2_UNSET.
  2968. .P
  2969. Offset values that correspond to unused groups at the end of the expression are
  2970. also set to PCRE2_UNSET. For example, if the string "abc" is matched against
  2971. the pattern (abc)(x(yz)?)? groups 2 and 3 are not matched. The return from the
  2972. function is 2, because the highest used capture group number is 1. The offsets
  2973. for for the second and third capture groupss (assuming the vector is large
  2974. enough, of course) are set to PCRE2_UNSET.
  2975. .P
  2976. Elements in the ovector that do not correspond to capturing parentheses in the
  2977. pattern are never changed. That is, if a pattern contains \fIn\fP capturing
  2978. parentheses, no more than \fIovector[0]\fP to \fIovector[2n+1]\fP are set by
  2979. \fBpcre2_match()\fP. The other elements retain whatever values they previously
  2980. had. After a failed match attempt, the contents of the ovector are unchanged.
  2981. .
  2982. .
  2983. .\" HTML <a name="matchotherdata"></a>
  2984. .SH "OTHER INFORMATION ABOUT A MATCH"
  2985. .rs
  2986. .sp
  2987. .nf
  2988. .B PCRE2_SPTR pcre2_get_mark(pcre2_match_data *\fImatch_data\fP);
  2989. .sp
  2990. .B PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *\fImatch_data\fP);
  2991. .fi
  2992. .P
  2993. As well as the offsets in the ovector, other information about a match is
  2994. retained in the match data block and can be retrieved by the above functions in
  2995. appropriate circumstances. If they are called at other times, the result is
  2996. undefined.
  2997. .P
  2998. After a successful match, a partial match (PCRE2_ERROR_PARTIAL), or a failure
  2999. to match (PCRE2_ERROR_NOMATCH), a mark name may be available. The function
  3000. \fBpcre2_get_mark()\fP can be called to access this name, which can be
  3001. specified in the pattern by any of the backtracking control verbs, not just
  3002. (*MARK). The same function applies to all the verbs. It returns a pointer to
  3003. the zero-terminated name, which is within the compiled pattern. If no name is
  3004. available, NULL is returned. The length of the name (excluding the terminating
  3005. zero) is stored in the code unit that precedes the name. You should use this
  3006. length instead of relying on the terminating zero if the name might contain a
  3007. binary zero.
  3008. .P
  3009. After a successful match, the name that is returned is the last mark name
  3010. encountered on the matching path through the pattern. Instances of backtracking
  3011. verbs without names do not count. Thus, for example, if the matching path
  3012. contains (*MARK:A)(*PRUNE), the name "A" is returned. After a "no match" or a
  3013. partial match, the last encountered name is returned. For example, consider
  3014. this pattern:
  3015. .sp
  3016. ^(*MARK:A)((*MARK:B)a|b)c
  3017. .sp
  3018. When it matches "bc", the returned name is A. The B mark is "seen" in the first
  3019. branch of the group, but it is not on the matching path. On the other hand,
  3020. when this pattern fails to match "bx", the returned name is B.
  3021. .P
  3022. \fBWarning:\fP By default, certain start-of-match optimizations are used to
  3023. give a fast "no match" result in some situations. For example, if the anchoring
  3024. is removed from the pattern above, there is an initial check for the presence
  3025. of "c" in the subject before running the matching engine. This check fails for
  3026. "bx", causing a match failure without seeing any marks. You can disable the
  3027. start-of-match optimizations by setting the PCRE2_NO_START_OPTIMIZE option for
  3028. \fBpcre2_compile()\fP or by starting the pattern with (*NO_START_OPT).
  3029. .P
  3030. After a successful match, a partial match, or one of the invalid UTF errors
  3031. (for example, PCRE2_ERROR_UTF8_ERR5), \fBpcre2_get_startchar()\fP can be
  3032. called. After a successful or partial match it returns the code unit offset of
  3033. the character at which the match started. For a non-partial match, this can be
  3034. different to the value of \fIovector[0]\fP if the pattern contains the \eK
  3035. escape sequence. After a partial match, however, this value is always the same
  3036. as \fIovector[0]\fP because \eK does not affect the result of a partial match.
  3037. .P
  3038. After a UTF check failure, \fBpcre2_get_startchar()\fP can be used to obtain
  3039. the code unit offset of the invalid UTF character. Details are given in the
  3040. .\" HREF
  3041. \fBpcre2unicode\fP
  3042. .\"
  3043. page.
  3044. .
  3045. .
  3046. .\" HTML <a name="errorlist"></a>
  3047. .SH "ERROR RETURNS FROM \fBpcre2_match()\fP"
  3048. .rs
  3049. .sp
  3050. If \fBpcre2_match()\fP fails, it returns a negative number. This can be
  3051. converted to a text string by calling the \fBpcre2_get_error_message()\fP
  3052. function (see "Obtaining a textual error message"
  3053. .\" HTML <a href="#geterrormessage">
  3054. .\" </a>
  3055. below).
  3056. .\"
  3057. Negative error codes are also returned by other functions, and are documented
  3058. with them. The codes are given names in the header file. If UTF checking is in
  3059. force and an invalid UTF subject string is detected, one of a number of
  3060. UTF-specific negative error codes is returned. Details are given in the
  3061. .\" HREF
  3062. \fBpcre2unicode\fP
  3063. .\"
  3064. page. The following are the other errors that may be returned by
  3065. \fBpcre2_match()\fP:
  3066. .sp
  3067. PCRE2_ERROR_NOMATCH
  3068. .sp
  3069. The subject string did not match the pattern.
  3070. .sp
  3071. PCRE2_ERROR_PARTIAL
  3072. .sp
  3073. The subject string did not match, but it did match partially. See the
  3074. .\" HREF
  3075. \fBpcre2partial\fP
  3076. .\"
  3077. documentation for details of partial matching.
  3078. .sp
  3079. PCRE2_ERROR_BADMAGIC
  3080. .sp
  3081. PCRE2 stores a 4-byte "magic number" at the start of the compiled code, to
  3082. catch the case when it is passed a junk pointer. This is the error that is
  3083. returned when the magic number is not present.
  3084. .sp
  3085. PCRE2_ERROR_BADMODE
  3086. .sp
  3087. This error is given when a compiled pattern is passed to a function in a
  3088. library of a different code unit width, for example, a pattern compiled by
  3089. the 8-bit library is passed to a 16-bit or 32-bit library function.
  3090. .sp
  3091. PCRE2_ERROR_BADOFFSET
  3092. .sp
  3093. The value of \fIstartoffset\fP was greater than the length of the subject.
  3094. .sp
  3095. PCRE2_ERROR_BADOPTION
  3096. .sp
  3097. An unrecognized bit was set in the \fIoptions\fP argument.
  3098. .sp
  3099. PCRE2_ERROR_BADUTFOFFSET
  3100. .sp
  3101. The UTF code unit sequence that was passed as a subject was checked and found
  3102. to be valid (the PCRE2_NO_UTF_CHECK option was not set), but the value of
  3103. \fIstartoffset\fP did not point to the beginning of a UTF character or the end
  3104. of the subject.
  3105. .sp
  3106. PCRE2_ERROR_CALLOUT
  3107. .sp
  3108. This error is never generated by \fBpcre2_match()\fP itself. It is provided for
  3109. use by callout functions that want to cause \fBpcre2_match()\fP or
  3110. \fBpcre2_callout_enumerate()\fP to return a distinctive error code. See the
  3111. .\" HREF
  3112. \fBpcre2callout\fP
  3113. .\"
  3114. documentation for details.
  3115. .sp
  3116. PCRE2_ERROR_DEPTHLIMIT
  3117. .sp
  3118. The nested backtracking depth limit was reached.
  3119. .sp
  3120. PCRE2_ERROR_HEAPLIMIT
  3121. .sp
  3122. The heap limit was reached.
  3123. .sp
  3124. PCRE2_ERROR_INTERNAL
  3125. .sp
  3126. An unexpected internal error has occurred. This error could be caused by a bug
  3127. in PCRE2 or by overwriting of the compiled pattern.
  3128. .sp
  3129. PCRE2_ERROR_JIT_STACKLIMIT
  3130. .sp
  3131. This error is returned when a pattern that was successfully studied using JIT
  3132. is being matched, but the memory available for the just-in-time processing
  3133. stack is not large enough. See the
  3134. .\" HREF
  3135. \fBpcre2jit\fP
  3136. .\"
  3137. documentation for more details.
  3138. .sp
  3139. PCRE2_ERROR_MATCHLIMIT
  3140. .sp
  3141. The backtracking match limit was reached.
  3142. .sp
  3143. PCRE2_ERROR_NOMEMORY
  3144. .sp
  3145. If a pattern contains many nested backtracking points, heap memory is used to
  3146. remember them. This error is given when the memory allocation function (default
  3147. or custom) fails. Note that a different error, PCRE2_ERROR_HEAPLIMIT, is given
  3148. if the amount of memory needed exceeds the heap limit. PCRE2_ERROR_NOMEMORY is
  3149. also returned if PCRE2_COPY_MATCHED_SUBJECT is set and memory allocation fails.
  3150. .sp
  3151. PCRE2_ERROR_NULL
  3152. .sp
  3153. Either the \fIcode\fP, \fIsubject\fP, or \fImatch_data\fP argument was passed
  3154. as NULL.
  3155. .sp
  3156. PCRE2_ERROR_RECURSELOOP
  3157. .sp
  3158. This error is returned when \fBpcre2_match()\fP detects a recursion loop within
  3159. the pattern. Specifically, it means that either the whole pattern or a
  3160. capture group has been called recursively for the second time at the same
  3161. position in the subject string. Some simple patterns that might do this are
  3162. detected and faulted at compile time, but more complicated cases, in particular
  3163. mutual recursions between two different groups, cannot be detected until
  3164. matching is attempted.
  3165. .
  3166. .
  3167. .\" HTML <a name="geterrormessage"></a>
  3168. .SH "OBTAINING A TEXTUAL ERROR MESSAGE"
  3169. .rs
  3170. .sp
  3171. .nf
  3172. .B int pcre2_get_error_message(int \fIerrorcode\fP, PCRE2_UCHAR *\fIbuffer\fP,
  3173. .B " PCRE2_SIZE \fIbufflen\fP);"
  3174. .fi
  3175. .P
  3176. A text message for an error code from any PCRE2 function (compile, match, or
  3177. auxiliary) can be obtained by calling \fBpcre2_get_error_message()\fP. The code
  3178. is passed as the first argument, with the remaining two arguments specifying a
  3179. code unit buffer and its length in code units, into which the text message is
  3180. placed. The message is returned in code units of the appropriate width for the
  3181. library that is being used.
  3182. .P
  3183. The returned message is terminated with a trailing zero, and the function
  3184. returns the number of code units used, excluding the trailing zero. If the
  3185. error number is unknown, the negative error code PCRE2_ERROR_BADDATA is
  3186. returned. If the buffer is too small, the message is truncated (but still with
  3187. a trailing zero), and the negative error code PCRE2_ERROR_NOMEMORY is returned.
  3188. None of the messages are very long; a buffer size of 120 code units is ample.
  3189. .
  3190. .
  3191. .\" HTML <a name="extractbynumber"></a>
  3192. .SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER"
  3193. .rs
  3194. .sp
  3195. .nf
  3196. .B int pcre2_substring_length_bynumber(pcre2_match_data *\fImatch_data\fP,
  3197. .B " uint32_t \fInumber\fP, PCRE2_SIZE *\fIlength\fP);"
  3198. .sp
  3199. .B int pcre2_substring_copy_bynumber(pcre2_match_data *\fImatch_data\fP,
  3200. .B " uint32_t \fInumber\fP, PCRE2_UCHAR *\fIbuffer\fP,"
  3201. .B " PCRE2_SIZE *\fIbufflen\fP);"
  3202. .sp
  3203. .B int pcre2_substring_get_bynumber(pcre2_match_data *\fImatch_data\fP,
  3204. .B " uint32_t \fInumber\fP, PCRE2_UCHAR **\fIbufferptr\fP,"
  3205. .B " PCRE2_SIZE *\fIbufflen\fP);"
  3206. .sp
  3207. .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP);
  3208. .fi
  3209. .P
  3210. Captured substrings can be accessed directly by using the ovector as described
  3211. .\" HTML <a href="#matchedstrings">
  3212. .\" </a>
  3213. above.
  3214. .\"
  3215. For convenience, auxiliary functions are provided for extracting captured
  3216. substrings as new, separate, zero-terminated strings. A substring that contains
  3217. a binary zero is correctly extracted and has a further zero added on the end,
  3218. but the result is not, of course, a C string.
  3219. .P
  3220. The functions in this section identify substrings by number. The number zero
  3221. refers to the entire matched substring, with higher numbers referring to
  3222. substrings captured by parenthesized groups. After a partial match, only
  3223. substring zero is available. An attempt to extract any other substring gives
  3224. the error PCRE2_ERROR_PARTIAL. The next section describes similar functions for
  3225. extracting captured substrings by name.
  3226. .P
  3227. If a pattern uses the \eK escape sequence within a positive assertion, the
  3228. reported start of a successful match can be greater than the end of the match.
  3229. For example, if the pattern (?=ab\eK) is matched against "ab", the start and
  3230. end offset values for the match are 2 and 0. In this situation, calling these
  3231. functions with a zero substring number extracts a zero-length empty string.
  3232. .P
  3233. You can find the length in code units of a captured substring without
  3234. extracting it by calling \fBpcre2_substring_length_bynumber()\fP. The first
  3235. argument is a pointer to the match data block, the second is the group number,
  3236. and the third is a pointer to a variable into which the length is placed. If
  3237. you just want to know whether or not the substring has been captured, you can
  3238. pass the third argument as NULL.
  3239. .P
  3240. The \fBpcre2_substring_copy_bynumber()\fP function copies a captured substring
  3241. into a supplied buffer, whereas \fBpcre2_substring_get_bynumber()\fP copies it
  3242. into new memory, obtained using the same memory allocation function that was
  3243. used for the match data block. The first two arguments of these functions are a
  3244. pointer to the match data block and a capture group number.
  3245. .P
  3246. The final arguments of \fBpcre2_substring_copy_bynumber()\fP are a pointer to
  3247. the buffer and a pointer to a variable that contains its length in code units.
  3248. This is updated to contain the actual number of code units used for the
  3249. extracted substring, excluding the terminating zero.
  3250. .P
  3251. For \fBpcre2_substring_get_bynumber()\fP the third and fourth arguments point
  3252. to variables that are updated with a pointer to the new memory and the number
  3253. of code units that comprise the substring, again excluding the terminating
  3254. zero. When the substring is no longer needed, the memory should be freed by
  3255. calling \fBpcre2_substring_free()\fP.
  3256. .P
  3257. The return value from all these functions is zero for success, or a negative
  3258. error code. If the pattern match failed, the match failure code is returned.
  3259. If a substring number greater than zero is used after a partial match,
  3260. PCRE2_ERROR_PARTIAL is returned. Other possible error codes are:
  3261. .sp
  3262. PCRE2_ERROR_NOMEMORY
  3263. .sp
  3264. The buffer was too small for \fBpcre2_substring_copy_bynumber()\fP, or the
  3265. attempt to get memory failed for \fBpcre2_substring_get_bynumber()\fP.
  3266. .sp
  3267. PCRE2_ERROR_NOSUBSTRING
  3268. .sp
  3269. There is no substring with that number in the pattern, that is, the number is
  3270. greater than the number of capturing parentheses.
  3271. .sp
  3272. PCRE2_ERROR_UNAVAILABLE
  3273. .sp
  3274. The substring number, though not greater than the number of captures in the
  3275. pattern, is greater than the number of slots in the ovector, so the substring
  3276. could not be captured.
  3277. .sp
  3278. PCRE2_ERROR_UNSET
  3279. .sp
  3280. The substring did not participate in the match. For example, if the pattern is
  3281. (abc)|(def) and the subject is "def", and the ovector contains at least two
  3282. capturing slots, substring number 1 is unset.
  3283. .
  3284. .
  3285. .SH "EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS"
  3286. .rs
  3287. .sp
  3288. .nf
  3289. .B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP,
  3290. .B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP);
  3291. .sp
  3292. .B void pcre2_substring_list_free(PCRE2_SPTR *\fIlist\fP);
  3293. .fi
  3294. .P
  3295. The \fBpcre2_substring_list_get()\fP function extracts all available substrings
  3296. and builds a list of pointers to them. It also (optionally) builds a second
  3297. list that contains their lengths (in code units), excluding a terminating zero
  3298. that is added to each of them. All this is done in a single block of memory
  3299. that is obtained using the same memory allocation function that was used to get
  3300. the match data block.
  3301. .P
  3302. This function must be called only after a successful match. If called after a
  3303. partial match, the error code PCRE2_ERROR_PARTIAL is returned.
  3304. .P
  3305. The address of the memory block is returned via \fIlistptr\fP, which is also
  3306. the start of the list of string pointers. The end of the list is marked by a
  3307. NULL pointer. The address of the list of lengths is returned via
  3308. \fIlengthsptr\fP. If your strings do not contain binary zeros and you do not
  3309. therefore need the lengths, you may supply NULL as the \fBlengthsptr\fP
  3310. argument to disable the creation of a list of lengths. The yield of the
  3311. function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the memory block
  3312. could not be obtained. When the list is no longer needed, it should be freed by
  3313. calling \fBpcre2_substring_list_free()\fP.
  3314. .P
  3315. If this function encounters a substring that is unset, which can happen when
  3316. capture group number \fIn+1\fP matches some part of the subject, but group
  3317. \fIn\fP has not been used at all, it returns an empty string. This can be
  3318. distinguished from a genuine zero-length substring by inspecting the
  3319. appropriate offset in the ovector, which contain PCRE2_UNSET for unset
  3320. substrings, or by calling \fBpcre2_substring_length_bynumber()\fP.
  3321. .
  3322. .
  3323. .\" HTML <a name="extractbyname"></a>
  3324. .SH "EXTRACTING CAPTURED SUBSTRINGS BY NAME"
  3325. .rs
  3326. .sp
  3327. .nf
  3328. .B int pcre2_substring_number_from_name(const pcre2_code *\fIcode\fP,
  3329. .B " PCRE2_SPTR \fIname\fP);"
  3330. .sp
  3331. .B int pcre2_substring_length_byname(pcre2_match_data *\fImatch_data\fP,
  3332. .B " PCRE2_SPTR \fIname\fP, PCRE2_SIZE *\fIlength\fP);"
  3333. .sp
  3334. .B int pcre2_substring_copy_byname(pcre2_match_data *\fImatch_data\fP,
  3335. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR *\fIbuffer\fP, PCRE2_SIZE *\fIbufflen\fP);"
  3336. .sp
  3337. .B int pcre2_substring_get_byname(pcre2_match_data *\fImatch_data\fP,
  3338. .B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR **\fIbufferptr\fP, PCRE2_SIZE *\fIbufflen\fP);"
  3339. .sp
  3340. .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP);
  3341. .fi
  3342. .P
  3343. To extract a substring by name, you first have to find associated number.
  3344. For example, for this pattern:
  3345. .sp
  3346. (a+)b(?<xxx>\ed+)...
  3347. .sp
  3348. the number of the capture group called "xxx" is 2. If the name is known to be
  3349. unique (PCRE2_DUPNAMES was not set), you can find the number from the name by
  3350. calling \fBpcre2_substring_number_from_name()\fP. The first argument is the
  3351. compiled pattern, and the second is the name. The yield of the function is the
  3352. group number, PCRE2_ERROR_NOSUBSTRING if there is no group with that name, or
  3353. PCRE2_ERROR_NOUNIQUESUBSTRING if there is more than one group with that name.
  3354. Given the number, you can extract the substring directly from the ovector, or
  3355. use one of the "bynumber" functions described above.
  3356. .P
  3357. For convenience, there are also "byname" functions that correspond to the
  3358. "bynumber" functions, the only difference being that the second argument is a
  3359. name instead of a number. If PCRE2_DUPNAMES is set and there are duplicate
  3360. names, these functions scan all the groups with the given name, and return the
  3361. captured substring from the first named group that is set.
  3362. .P
  3363. If there are no groups with the given name, PCRE2_ERROR_NOSUBSTRING is
  3364. returned. If all groups with the name have numbers that are greater than the
  3365. number of slots in the ovector, PCRE2_ERROR_UNAVAILABLE is returned. If there
  3366. is at least one group with a slot in the ovector, but no group is found to be
  3367. set, PCRE2_ERROR_UNSET is returned.
  3368. .P
  3369. \fBWarning:\fP If the pattern uses the (?| feature to set up multiple
  3370. capture groups with the same number, as described in the
  3371. .\" HTML <a href="pcre2pattern.html#dupgroupnumber">
  3372. .\" </a>
  3373. section on duplicate group numbers
  3374. .\"
  3375. in the
  3376. .\" HREF
  3377. \fBpcre2pattern\fP
  3378. .\"
  3379. page, you cannot use names to distinguish the different capture groups, because
  3380. names are not included in the compiled code. The matching process uses only
  3381. numbers. For this reason, the use of different names for groups with the
  3382. same number causes an error at compile time.
  3383. .
  3384. .
  3385. .\" HTML <a name="substitutions"></a>
  3386. .SH "CREATING A NEW STRING WITH SUBSTITUTIONS"
  3387. .rs
  3388. .sp
  3389. .nf
  3390. .B int pcre2_substitute(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  3391. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  3392. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  3393. .B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacement\fP,"
  3394. .B " PCRE2_SIZE \fIrlength\fP, PCRE2_UCHAR *\fIoutputbuffer\fP,"
  3395. .B " PCRE2_SIZE *\fIoutlengthptr\fP);"
  3396. .fi
  3397. .P
  3398. This function optionally calls \fBpcre2_match()\fP and then makes a copy of the
  3399. subject string in \fIoutputbuffer\fP, replacing parts that were matched with
  3400. the \fIreplacement\fP string, whose length is supplied in \fBrlength\fP. This
  3401. can be given as PCRE2_ZERO_TERMINATED for a zero-terminated string. There is an
  3402. option (see PCRE2_SUBSTITUTE_REPLACEMENT_ONLY below) to return just the
  3403. replacement string(s). The default action is to perform just one replacement if
  3404. the pattern matches, but there is an option that requests multiple replacements
  3405. (see PCRE2_SUBSTITUTE_GLOBAL below).
  3406. .P
  3407. If successful, \fBpcre2_substitute()\fP returns the number of substitutions
  3408. that were carried out. This may be zero if no match was found, and is never
  3409. greater than one unless PCRE2_SUBSTITUTE_GLOBAL is set. A negative value is
  3410. returned if an error is detected.
  3411. .P
  3412. Matches in which a \eK item in a lookahead in the pattern causes the match to
  3413. end before it starts are not supported, and give rise to an error return. For
  3414. global replacements, matches in which \eK in a lookbehind causes the match to
  3415. start earlier than the point that was reached in the previous iteration are
  3416. also not supported.
  3417. .P
  3418. The first seven arguments of \fBpcre2_substitute()\fP are the same as for
  3419. \fBpcre2_match()\fP, except that the partial matching options are not
  3420. permitted, and \fImatch_data\fP may be passed as NULL, in which case a match
  3421. data block is obtained and freed within this function, using memory management
  3422. functions from the match context, if provided, or else those that were used to
  3423. allocate memory for the compiled code.
  3424. .P
  3425. If \fImatch_data\fP is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the
  3426. provided block is used for all calls to \fBpcre2_match()\fP, and its contents
  3427. afterwards are the result of the final call. For global changes, this will
  3428. always be a no-match error. The contents of the ovector within the match data
  3429. block may or may not have been changed.
  3430. .P
  3431. As well as the usual options for \fBpcre2_match()\fP, a number of additional
  3432. options can be set in the \fIoptions\fP argument of \fBpcre2_substitute()\fP.
  3433. One such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external
  3434. \fImatch_data\fP block must be provided, and it must have been used for an
  3435. external call to \fBpcre2_match()\fP. The data in the \fImatch_data\fP block
  3436. (return code, offset vector) is used for the first substitution instead of
  3437. calling \fBpcre2_match()\fP from within \fBpcre2_substitute()\fP. This allows
  3438. an application to check for a match before choosing to substitute, without
  3439. having to repeat the match.
  3440. .P
  3441. The contents of the externally supplied match data block are not changed when
  3442. PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTITUTE_GLOBAL is also set,
  3443. \fBpcre2_match()\fP is called after the first substitution to check for further
  3444. matches, but this is done using an internally obtained match data block, thus
  3445. always leaving the external block unchanged.
  3446. .P
  3447. The \fIcode\fP argument is not used for matching before the first substitution
  3448. when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, even when
  3449. PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains information such as the
  3450. UTF setting and the number of capturing parentheses in the pattern.
  3451. .P
  3452. The default action of \fBpcre2_substitute()\fP is to return a copy of the
  3453. subject string with matched substrings replaced. However, if
  3454. PCRE2_SUBSTITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are
  3455. returned. In the global case, multiple replacements are concatenated in the
  3456. output buffer. Substitution callouts (see
  3457. .\" HTML <a href="#subcallouts">
  3458. .\" </a>
  3459. below)
  3460. .\"
  3461. can be used to separate them if necessary.
  3462. .P
  3463. The \fIoutlengthptr\fP argument of \fBpcre2_substitute()\fP must point to a
  3464. variable that contains the length, in code units, of the output buffer. If the
  3465. function is successful, the value is updated to contain the length in code
  3466. units of the new string, excluding the trailing zero that is automatically
  3467. added.
  3468. .P
  3469. If the function is not successful, the value set via \fIoutlengthptr\fP depends
  3470. on the type of error. For syntax errors in the replacement string, the value is
  3471. the offset in the replacement string where the error was detected. For other
  3472. errors, the value is PCRE2_UNSET by default. This includes the case of the
  3473. output buffer being too small, unless PCRE2_SUBSTITUTE_OVERFLOW_LENGTH is set.
  3474. .P
  3475. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH changes what happens when the output buffer is
  3476. too small. The default action is to return PCRE2_ERROR_NOMEMORY immediately. If
  3477. this option is set, however, \fBpcre2_substitute()\fP continues to go through
  3478. the motions of matching and substituting (without, of course, writing anything)
  3479. in order to compute the size of buffer that is needed. This value is passed
  3480. back via the \fIoutlengthptr\fP variable, with the result of the function still
  3481. being PCRE2_ERROR_NOMEMORY.
  3482. .P
  3483. Passing a buffer size of zero is a permitted way of finding out how much memory
  3484. is needed for given substitution. However, this does mean that the entire
  3485. operation is carried out twice. Depending on the application, it may be more
  3486. efficient to allocate a large buffer and free the excess afterwards, instead of
  3487. using PCRE2_SUBSTITUTE_OVERFLOW_LENGTH.
  3488. .P
  3489. The replacement string, which is interpreted as a UTF string in UTF mode, is
  3490. checked for UTF validity unless PCRE2_NO_UTF_CHECK is set. An invalid UTF
  3491. replacement string causes an immediate return with the relevant UTF error code.
  3492. .P
  3493. If PCRE2_SUBSTITUTE_LITERAL is set, the replacement string is not interpreted
  3494. in any way. By default, however, a dollar character is an escape character that
  3495. can specify the insertion of characters from capture groups and names from
  3496. (*MARK) or other control verbs in the pattern. The following forms are always
  3497. recognized:
  3498. .sp
  3499. $$ insert a dollar character
  3500. $<n> or ${<n>} insert the contents of group <n>
  3501. $*MARK or ${*MARK} insert a control verb name
  3502. .sp
  3503. Either a group number or a group name can be given for <n>. Curly brackets are
  3504. required only if the following character would be interpreted as part of the
  3505. number or name. The number may be zero to include the entire matched string.
  3506. For example, if the pattern a(b)c is matched with "=abc=" and the replacement
  3507. string "+$1$0$1+", the result is "=+babcb+=".
  3508. .P
  3509. $*MARK inserts the name from the last encountered backtracking control verb on
  3510. the matching path that has a name. (*MARK) must always include a name, but the
  3511. other verbs need not. For example, in the case of (*MARK:A)(*PRUNE) the name
  3512. inserted is "A", but for (*MARK:A)(*PRUNE:B) the relevant name is "B". This
  3513. facility can be used to perform simple simultaneous substitutions, as this
  3514. \fBpcre2test\fP example shows:
  3515. .sp
  3516. /(*MARK:pear)apple|(*MARK:orange)lemon/g,replace=${*MARK}
  3517. apple lemon
  3518. 2: pear orange
  3519. .sp
  3520. PCRE2_SUBSTITUTE_GLOBAL causes the function to iterate over the subject string,
  3521. replacing every matching substring. If this option is not set, only the first
  3522. matching substring is replaced. The search for matches takes place in the
  3523. original subject string (that is, previous replacements do not affect it).
  3524. Iteration is implemented by advancing the \fIstartoffset\fP value for each
  3525. search, which is always passed the entire subject string. If an offset limit is
  3526. set in the match context, searching stops when that limit is reached.
  3527. .P
  3528. You can restrict the effect of a global substitution to a portion of the
  3529. subject string by setting either or both of \fIstartoffset\fP and an offset
  3530. limit. Here is a \fBpcre2test\fP example:
  3531. .sp
  3532. /B/g,replace=!,use_offset_limit
  3533. ABC ABC ABC ABC\e=offset=3,offset_limit=12
  3534. 2: ABC A!C A!C ABC
  3535. .sp
  3536. When continuing with global substitutions after matching a substring with zero
  3537. length, an attempt to find a non-empty match at the same offset is performed.
  3538. If this is not successful, the offset is advanced by one character except when
  3539. CRLF is a valid newline sequence and the next two characters are CR, LF. In
  3540. this case, the offset is advanced by two characters.
  3541. .P
  3542. PCRE2_SUBSTITUTE_UNKNOWN_UNSET causes references to capture groups that do
  3543. not appear in the pattern to be treated as unset groups. This option should be
  3544. used with care, because it means that a typo in a group name or number no
  3545. longer causes the PCRE2_ERROR_NOSUBSTRING error.
  3546. .P
  3547. PCRE2_SUBSTITUTE_UNSET_EMPTY causes unset capture groups (including unknown
  3548. groups when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) to be treated as empty
  3549. strings when inserted as described above. If this option is not set, an attempt
  3550. to insert an unset group causes the PCRE2_ERROR_UNSET error. This option does
  3551. not influence the extended substitution syntax described below.
  3552. .P
  3553. PCRE2_SUBSTITUTE_EXTENDED causes extra processing to be applied to the
  3554. replacement string. Without this option, only the dollar character is special,
  3555. and only the group insertion forms listed above are valid. When
  3556. PCRE2_SUBSTITUTE_EXTENDED is set, two things change:
  3557. .P
  3558. Firstly, backslash in a replacement string is interpreted as an escape
  3559. character. The usual forms such as \en or \ex{ddd} can be used to specify
  3560. particular character codes, and backslash followed by any non-alphanumeric
  3561. character quotes that character. Extended quoting can be coded using \eQ...\eE,
  3562. exactly as in pattern strings.
  3563. .P
  3564. There are also four escape sequences for forcing the case of inserted letters.
  3565. The insertion mechanism has three states: no case forcing, force upper case,
  3566. and force lower case. The escape sequences change the current state: \eU and
  3567. \eL change to upper or lower case forcing, respectively, and \eE (when not
  3568. terminating a \eQ quoted sequence) reverts to no case forcing. The sequences
  3569. \eu and \el force the next character (if it is a letter) to upper or lower
  3570. case, respectively, and then the state automatically reverts to no case
  3571. forcing. Case forcing applies to all inserted characters, including those from
  3572. capture groups and letters within \eQ...\eE quoted sequences. If either
  3573. PCRE2_UTF or PCRE2_UCP was set when the pattern was compiled, Unicode
  3574. properties are used for case forcing characters whose code points are greater
  3575. than 127.
  3576. .P
  3577. Note that case forcing sequences such as \eU...\eE do not nest. For example,
  3578. the result of processing "\eUaa\eLBB\eEcc\eE" is "AAbbcc"; the final \eE has no
  3579. effect. Note also that the PCRE2_ALT_BSUX and PCRE2_EXTRA_ALT_BSUX options do
  3580. not apply to replacement strings.
  3581. .P
  3582. The second effect of setting PCRE2_SUBSTITUTE_EXTENDED is to add more
  3583. flexibility to capture group substitution. The syntax is similar to that used
  3584. by Bash:
  3585. .sp
  3586. ${<n>:-<string>}
  3587. ${<n>:+<string1>:<string2>}
  3588. .sp
  3589. As before, <n> may be a group number or a name. The first form specifies a
  3590. default value. If group <n> is set, its value is inserted; if not, <string> is
  3591. expanded and the result inserted. The second form specifies strings that are
  3592. expanded and inserted when group <n> is set or unset, respectively. The first
  3593. form is just a convenient shorthand for
  3594. .sp
  3595. ${<n>:+${<n>}:<string>}
  3596. .sp
  3597. Backslash can be used to escape colons and closing curly brackets in the
  3598. replacement strings. A change of the case forcing state within a replacement
  3599. string remains in force afterwards, as shown in this \fBpcre2test\fP example:
  3600. .sp
  3601. /(some)?(body)/substitute_extended,replace=${1:+\eU:\eL}HeLLo
  3602. body
  3603. 1: hello
  3604. somebody
  3605. 1: HELLO
  3606. .sp
  3607. The PCRE2_SUBSTITUTE_UNSET_EMPTY option does not affect these extended
  3608. substitutions. However, PCRE2_SUBSTITUTE_UNKNOWN_UNSET does cause unknown
  3609. groups in the extended syntax forms to be treated as unset.
  3610. .P
  3611. If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_UNKNOWN_UNSET,
  3612. PCRE2_SUBSTITUTE_UNSET_EMPTY, and PCRE2_SUBSTITUTE_EXTENDED are irrelevant and
  3613. are ignored.
  3614. .
  3615. .
  3616. .SS "Substitution errors"
  3617. .rs
  3618. .sp
  3619. In the event of an error, \fBpcre2_substitute()\fP returns a negative error
  3620. code. Except for PCRE2_ERROR_NOMATCH (which is never returned), errors from
  3621. \fBpcre2_match()\fP are passed straight back.
  3622. .P
  3623. PCRE2_ERROR_NOSUBSTRING is returned for a non-existent substring insertion,
  3624. unless PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set.
  3625. .P
  3626. PCRE2_ERROR_UNSET is returned for an unset substring insertion (including an
  3627. unknown substring when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) when the simple
  3628. (non-extended) syntax is used and PCRE2_SUBSTITUTE_UNSET_EMPTY is not set.
  3629. .P
  3630. PCRE2_ERROR_NOMEMORY is returned if the output buffer is not big enough. If the
  3631. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set, the size of buffer that is
  3632. needed is returned via \fIoutlengthptr\fP. Note that this does not happen by
  3633. default.
  3634. .P
  3635. PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the
  3636. \fImatch_data\fP argument is NULL.
  3637. .P
  3638. PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the
  3639. replacement string, with more particular errors being PCRE2_ERROR_BADREPESCAPE
  3640. (invalid escape sequence), PCRE2_ERROR_REPMISSINGBRACE (closing curly bracket
  3641. not found), PCRE2_ERROR_BADSUBSTITUTION (syntax error in extended group
  3642. substitution), and PCRE2_ERROR_BADSUBSPATTERN (the pattern match ended before
  3643. it started or the match started earlier than the current position in the
  3644. subject, which can happen if \eK is used in an assertion).
  3645. .P
  3646. As for all PCRE2 errors, a text message that describes the error can be
  3647. obtained by calling the \fBpcre2_get_error_message()\fP function (see
  3648. "Obtaining a textual error message"
  3649. .\" HTML <a href="#geterrormessage">
  3650. .\" </a>
  3651. above).
  3652. .\"
  3653. .
  3654. .
  3655. .\" HTML <a name="subcallouts"></a>
  3656. .SS "Substitution callouts"
  3657. .rs
  3658. .sp
  3659. .nf
  3660. .B int pcre2_set_substitute_callout(pcre2_match_context *\fImcontext\fP,
  3661. .B " int (*\fIcallout_function\fP)(pcre2_substitute_callout_block *, void *),"
  3662. .B " void *\fIcallout_data\fP);"
  3663. .fi
  3664. .sp
  3665. The \fBpcre2_set_substitution_callout()\fP function can be used to specify a
  3666. callout function for \fBpcre2_substitute()\fP. This information is passed in
  3667. a match context. The callout function is called after each substitution has
  3668. been processed, but it can cause the replacement not to happen. The callout
  3669. function is not called for simulated substitutions that happen as a result of
  3670. the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option.
  3671. .P
  3672. The first argument of the callout function is a pointer to a substitute callout
  3673. block structure, which contains the following fields, not necessarily in this
  3674. order:
  3675. .sp
  3676. uint32_t \fIversion\fP;
  3677. uint32_t \fIsubscount\fP;
  3678. PCRE2_SPTR \fIinput\fP;
  3679. PCRE2_SPTR \fIoutput\fP;
  3680. PCRE2_SIZE \fI*ovector\fP;
  3681. uint32_t \fIoveccount\fP;
  3682. PCRE2_SIZE \fIoutput_offsets[2]\fP;
  3683. .sp
  3684. The \fIversion\fP field contains the version number of the block format. The
  3685. current version is 0. The version number will increase in future if more fields
  3686. are added, but the intention is never to remove any of the existing fields.
  3687. .P
  3688. The \fIsubscount\fP field is the number of the current match. It is 1 for the
  3689. first callout, 2 for the second, and so on. The \fIinput\fP and \fIoutput\fP
  3690. pointers are copies of the values passed to \fBpcre2_substitute()\fP.
  3691. .P
  3692. The \fIovector\fP field points to the ovector, which contains the result of the
  3693. most recent match. The \fIoveccount\fP field contains the number of pairs that
  3694. are set in the ovector, and is always greater than zero.
  3695. .P
  3696. The \fIoutput_offsets\fP vector contains the offsets of the replacement in the
  3697. output string. This has already been processed for dollar and (if requested)
  3698. backslash substitutions as described above.
  3699. .P
  3700. The second argument of the callout function is the value passed as
  3701. \fIcallout_data\fP when the function was registered. The value returned by the
  3702. callout function is interpreted as follows:
  3703. .P
  3704. If the value is zero, the replacement is accepted, and, if
  3705. PCRE2_SUBSTITUTE_GLOBAL is set, processing continues with a search for the next
  3706. match. If the value is not zero, the current replacement is not accepted. If
  3707. the value is greater than zero, processing continues when
  3708. PCRE2_SUBSTITUTE_GLOBAL is set. Otherwise (the value is less than zero or
  3709. PCRE2_SUBSTITUTE_GLOBAL is not set), the the rest of the input is copied to the
  3710. output and the call to \fBpcre2_substitute()\fP exits, returning the number of
  3711. matches so far.
  3712. .
  3713. .
  3714. .SH "DUPLICATE CAPTURE GROUP NAMES"
  3715. .rs
  3716. .sp
  3717. .nf
  3718. .B int pcre2_substring_nametable_scan(const pcre2_code *\fIcode\fP,
  3719. .B " PCRE2_SPTR \fIname\fP, PCRE2_SPTR *\fIfirst\fP, PCRE2_SPTR *\fIlast\fP);"
  3720. .fi
  3721. .P
  3722. When a pattern is compiled with the PCRE2_DUPNAMES option, names for capture
  3723. groups are not required to be unique. Duplicate names are always allowed for
  3724. groups with the same number, created by using the (?| feature. Indeed, if such
  3725. groups are named, they are required to use the same names.
  3726. .P
  3727. Normally, patterns that use duplicate names are such that in any one match,
  3728. only one of each set of identically-named groups participates. An example is
  3729. shown in the
  3730. .\" HREF
  3731. \fBpcre2pattern\fP
  3732. .\"
  3733. documentation.
  3734. .P
  3735. When duplicates are present, \fBpcre2_substring_copy_byname()\fP and
  3736. \fBpcre2_substring_get_byname()\fP return the first substring corresponding to
  3737. the given name that is set. Only if none are set is PCRE2_ERROR_UNSET is
  3738. returned. The \fBpcre2_substring_number_from_name()\fP function returns the
  3739. error PCRE2_ERROR_NOUNIQUESUBSTRING when there are duplicate names.
  3740. .P
  3741. If you want to get full details of all captured substrings for a given name,
  3742. you must use the \fBpcre2_substring_nametable_scan()\fP function. The first
  3743. argument is the compiled pattern, and the second is the name. If the third and
  3744. fourth arguments are NULL, the function returns a group number for a unique
  3745. name, or PCRE2_ERROR_NOUNIQUESUBSTRING otherwise.
  3746. .P
  3747. When the third and fourth arguments are not NULL, they must be pointers to
  3748. variables that are updated by the function. After it has run, they point to the
  3749. first and last entries in the name-to-number table for the given name, and the
  3750. function returns the length of each entry in code units. In both cases,
  3751. PCRE2_ERROR_NOSUBSTRING is returned if there are no entries for the given name.
  3752. .P
  3753. The format of the name table is described
  3754. .\" HTML <a href="#infoaboutpattern">
  3755. .\" </a>
  3756. above
  3757. .\"
  3758. in the section entitled \fIInformation about a pattern\fP. Given all the
  3759. relevant entries for the name, you can extract each of their numbers, and hence
  3760. the captured data.
  3761. .
  3762. .
  3763. .SH "FINDING ALL POSSIBLE MATCHES AT ONE POSITION"
  3764. .rs
  3765. .sp
  3766. The traditional matching function uses a similar algorithm to Perl, which stops
  3767. when it finds the first match at a given point in the subject. If you want to
  3768. find all possible matches, or the longest possible match at a given position,
  3769. consider using the alternative matching function (see below) instead. If you
  3770. cannot use the alternative function, you can kludge it up by making use of the
  3771. callout facility, which is described in the
  3772. .\" HREF
  3773. \fBpcre2callout\fP
  3774. .\"
  3775. documentation.
  3776. .P
  3777. What you have to do is to insert a callout right at the end of the pattern.
  3778. When your callout function is called, extract and save the current matched
  3779. substring. Then return 1, which forces \fBpcre2_match()\fP to backtrack and try
  3780. other alternatives. Ultimately, when it runs out of matches,
  3781. \fBpcre2_match()\fP will yield PCRE2_ERROR_NOMATCH.
  3782. .
  3783. .
  3784. .\" HTML <a name="dfamatch"></a>
  3785. .SH "MATCHING A PATTERN: THE ALTERNATIVE FUNCTION"
  3786. .rs
  3787. .sp
  3788. .nf
  3789. .B int pcre2_dfa_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  3790. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  3791. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  3792. .B " pcre2_match_context *\fImcontext\fP,"
  3793. .B " int *\fIworkspace\fP, PCRE2_SIZE \fIwscount\fP);"
  3794. .fi
  3795. .P
  3796. The function \fBpcre2_dfa_match()\fP is called to match a subject string
  3797. against a compiled pattern, using a matching algorithm that scans the subject
  3798. string just once (not counting lookaround assertions), and does not backtrack.
  3799. This has different characteristics to the normal algorithm, and is not
  3800. compatible with Perl. Some of the features of PCRE2 patterns are not supported.
  3801. Nevertheless, there are times when this kind of matching can be useful. For a
  3802. discussion of the two matching algorithms, and a list of features that
  3803. \fBpcre2_dfa_match()\fP does not support, see the
  3804. .\" HREF
  3805. \fBpcre2matching\fP
  3806. .\"
  3807. documentation.
  3808. .P
  3809. The arguments for the \fBpcre2_dfa_match()\fP function are the same as for
  3810. \fBpcre2_match()\fP, plus two extras. The ovector within the match data block
  3811. is used in a different way, and this is described below. The other common
  3812. arguments are used in the same way as for \fBpcre2_match()\fP, so their
  3813. description is not repeated here.
  3814. .P
  3815. The two additional arguments provide workspace for the function. The workspace
  3816. vector should contain at least 20 elements. It is used for keeping track of
  3817. multiple paths through the pattern tree. More workspace is needed for patterns
  3818. and subjects where there are a lot of potential matches.
  3819. .P
  3820. Here is an example of a simple call to \fBpcre2_dfa_match()\fP:
  3821. .sp
  3822. int wspace[20];
  3823. pcre2_match_data *md = pcre2_match_data_create(4, NULL);
  3824. int rc = pcre2_dfa_match(
  3825. re, /* result of pcre2_compile() */
  3826. "some string", /* the subject string */
  3827. 11, /* the length of the subject string */
  3828. 0, /* start at offset 0 in the subject */
  3829. 0, /* default options */
  3830. md, /* the match data block */
  3831. NULL, /* a match context; NULL means use defaults */
  3832. wspace, /* working space vector */
  3833. 20); /* number of elements (NOT size in bytes) */
  3834. .
  3835. .SS "Option bits for \fBpcre_dfa_match()\fP"
  3836. .rs
  3837. .sp
  3838. The unused bits of the \fIoptions\fP argument for \fBpcre2_dfa_match()\fP must
  3839. be zero. The only bits that may be set are PCRE2_ANCHORED,
  3840. PCRE2_COPY_MATCHED_SUBJECT, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL,
  3841. PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_UTF_CHECK, PCRE2_PARTIAL_HARD,
  3842. PCRE2_PARTIAL_SOFT, PCRE2_DFA_SHORTEST, and PCRE2_DFA_RESTART. All but the last
  3843. four of these are exactly the same as for \fBpcre2_match()\fP, so their
  3844. description is not repeated here.
  3845. .sp
  3846. PCRE2_PARTIAL_HARD
  3847. PCRE2_PARTIAL_SOFT
  3848. .sp
  3849. These have the same general effect as they do for \fBpcre2_match()\fP, but the
  3850. details are slightly different. When PCRE2_PARTIAL_HARD is set for
  3851. \fBpcre2_dfa_match()\fP, it returns PCRE2_ERROR_PARTIAL if the end of the
  3852. subject is reached and there is still at least one matching possibility that
  3853. requires additional characters. This happens even if some complete matches have
  3854. already been found. When PCRE2_PARTIAL_SOFT is set, the return code
  3855. PCRE2_ERROR_NOMATCH is converted into PCRE2_ERROR_PARTIAL if the end of the
  3856. subject is reached, there have been no complete matches, but there is still at
  3857. least one matching possibility. The portion of the string that was inspected
  3858. when the longest partial match was found is set as the first matching string in
  3859. both cases. There is a more detailed discussion of partial and multi-segment
  3860. matching, with examples, in the
  3861. .\" HREF
  3862. \fBpcre2partial\fP
  3863. .\"
  3864. documentation.
  3865. .sp
  3866. PCRE2_DFA_SHORTEST
  3867. .sp
  3868. Setting the PCRE2_DFA_SHORTEST option causes the matching algorithm to stop as
  3869. soon as it has found one match. Because of the way the alternative algorithm
  3870. works, this is necessarily the shortest possible match at the first possible
  3871. matching point in the subject string.
  3872. .sp
  3873. PCRE2_DFA_RESTART
  3874. .sp
  3875. When \fBpcre2_dfa_match()\fP returns a partial match, it is possible to call it
  3876. again, with additional subject characters, and have it continue with the same
  3877. match. The PCRE2_DFA_RESTART option requests this action; when it is set, the
  3878. \fIworkspace\fP and \fIwscount\fP options must reference the same vector as
  3879. before because data about the match so far is left in them after a partial
  3880. match. There is more discussion of this facility in the
  3881. .\" HREF
  3882. \fBpcre2partial\fP
  3883. .\"
  3884. documentation.
  3885. .
  3886. .
  3887. .SS "Successful returns from \fBpcre2_dfa_match()\fP"
  3888. .rs
  3889. .sp
  3890. When \fBpcre2_dfa_match()\fP succeeds, it may have matched more than one
  3891. substring in the subject. Note, however, that all the matches from one run of
  3892. the function start at the same point in the subject. The shorter matches are
  3893. all initial substrings of the longer matches. For example, if the pattern
  3894. .sp
  3895. <.*>
  3896. .sp
  3897. is matched against the string
  3898. .sp
  3899. This is <something> <something else> <something further> no more
  3900. .sp
  3901. the three matched strings are
  3902. .sp
  3903. <something> <something else> <something further>
  3904. <something> <something else>
  3905. <something>
  3906. .sp
  3907. On success, the yield of the function is a number greater than zero, which is
  3908. the number of matched substrings. The offsets of the substrings are returned in
  3909. the ovector, and can be extracted by number in the same way as for
  3910. \fBpcre2_match()\fP, but the numbers bear no relation to any capture groups
  3911. that may exist in the pattern, because DFA matching does not support capturing.
  3912. .P
  3913. Calls to the convenience functions that extract substrings by name
  3914. return the error PCRE2_ERROR_DFA_UFUNC (unsupported function) if used after a
  3915. DFA match. The convenience functions that extract substrings by number never
  3916. return PCRE2_ERROR_NOSUBSTRING.
  3917. .P
  3918. The matched strings are stored in the ovector in reverse order of length; that
  3919. is, the longest matching string is first. If there were too many matches to fit
  3920. into the ovector, the yield of the function is zero, and the vector is filled
  3921. with the longest matches.
  3922. .P
  3923. NOTE: PCRE2's "auto-possessification" optimization usually applies to character
  3924. repeats at the end of a pattern (as well as internally). For example, the
  3925. pattern "a\ed+" is compiled as if it were "a\ed++". For DFA matching, this
  3926. means that only one possible match is found. If you really do want multiple
  3927. matches in such cases, either use an ungreedy repeat such as "a\ed+?" or set
  3928. the PCRE2_NO_AUTO_POSSESS option when compiling.
  3929. .
  3930. .
  3931. .SS "Error returns from \fBpcre2_dfa_match()\fP"
  3932. .rs
  3933. .sp
  3934. The \fBpcre2_dfa_match()\fP function returns a negative number when it fails.
  3935. Many of the errors are the same as for \fBpcre2_match()\fP, as described
  3936. .\" HTML <a href="#errorlist">
  3937. .\" </a>
  3938. above.
  3939. .\"
  3940. There are in addition the following errors that are specific to
  3941. \fBpcre2_dfa_match()\fP:
  3942. .sp
  3943. PCRE2_ERROR_DFA_UITEM
  3944. .sp
  3945. This return is given if \fBpcre2_dfa_match()\fP encounters an item in the
  3946. pattern that it does not support, for instance, the use of \eC in a UTF mode or
  3947. a backreference.
  3948. .sp
  3949. PCRE2_ERROR_DFA_UCOND
  3950. .sp
  3951. This return is given if \fBpcre2_dfa_match()\fP encounters a condition item
  3952. that uses a backreference for the condition, or a test for recursion in a
  3953. specific capture group. These are not supported.
  3954. .sp
  3955. PCRE2_ERROR_DFA_UINVALID_UTF
  3956. .sp
  3957. This return is given if \fBpcre2_dfa_match()\fP is called for a pattern that
  3958. was compiled with PCRE2_MATCH_INVALID_UTF. This is not supported for DFA
  3959. matching.
  3960. .sp
  3961. PCRE2_ERROR_DFA_WSSIZE
  3962. .sp
  3963. This return is given if \fBpcre2_dfa_match()\fP runs out of space in the
  3964. \fIworkspace\fP vector.
  3965. .sp
  3966. PCRE2_ERROR_DFA_RECURSE
  3967. .sp
  3968. When a recursion or subroutine call is processed, the matching function calls
  3969. itself recursively, using private memory for the ovector and \fIworkspace\fP.
  3970. This error is given if the internal ovector is not large enough. This should be
  3971. extremely rare, as a vector of size 1000 is used.
  3972. .sp
  3973. PCRE2_ERROR_DFA_BADRESTART
  3974. .sp
  3975. When \fBpcre2_dfa_match()\fP is called with the \fBPCRE2_DFA_RESTART\fP option,
  3976. some plausibility checks are made on the contents of the workspace, which
  3977. should contain data about the previous partial match. If any of these checks
  3978. fail, this error is given.
  3979. .
  3980. .
  3981. .SH "SEE ALSO"
  3982. .rs
  3983. .sp
  3984. \fBpcre2build\fP(3), \fBpcre2callout\fP(3), \fBpcre2demo(3)\fP,
  3985. \fBpcre2matching\fP(3), \fBpcre2partial\fP(3), \fBpcre2posix\fP(3),
  3986. \fBpcre2sample\fP(3), \fBpcre2unicode\fP(3).
  3987. .
  3988. .
  3989. .SH AUTHOR
  3990. .rs
  3991. .sp
  3992. .nf
  3993. Philip Hazel
  3994. University Computing Service
  3995. Cambridge, England.
  3996. .fi
  3997. .
  3998. .
  3999. .SH REVISION
  4000. .rs
  4001. .sp
  4002. .nf
  4003. Last updated: 04 November 2020
  4004. Copyright (c) 1997-2020 University of Cambridge.
  4005. .fi