16af9a77bSJohn Marino.\" Copyright (c) 1992, 1993, 1994 Henry Spencer. 26af9a77bSJohn Marino.\" Copyright (c) 1992, 1993, 1994 36af9a77bSJohn Marino.\" The Regents of the University of California. All rights reserved. 46af9a77bSJohn Marino.\" 56af9a77bSJohn Marino.\" This code is derived from software contributed to Berkeley by 66af9a77bSJohn Marino.\" Henry Spencer. 76af9a77bSJohn Marino.\" 86af9a77bSJohn Marino.\" Redistribution and use in source and binary forms, with or without 96af9a77bSJohn Marino.\" modification, are permitted provided that the following conditions 106af9a77bSJohn Marino.\" are met: 116af9a77bSJohn Marino.\" 1. Redistributions of source code must retain the above copyright 126af9a77bSJohn Marino.\" notice, this list of conditions and the following disclaimer. 136af9a77bSJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 146af9a77bSJohn Marino.\" notice, this list of conditions and the following disclaimer in the 156af9a77bSJohn Marino.\" documentation and/or other materials provided with the distribution. 166af9a77bSJohn Marino.\" 3. Neither the name of the University nor the names of its contributors 176af9a77bSJohn Marino.\" may be used to endorse or promote products derived from this software 186af9a77bSJohn Marino.\" without specific prior written permission. 196af9a77bSJohn Marino.\" 206af9a77bSJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 216af9a77bSJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 226af9a77bSJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 236af9a77bSJohn Marino.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 246af9a77bSJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 256af9a77bSJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 266af9a77bSJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 276af9a77bSJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 286af9a77bSJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 296af9a77bSJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 306af9a77bSJohn Marino.\" SUCH DAMAGE. 316af9a77bSJohn Marino.\" 326af9a77bSJohn Marino.\" @(#)regex.3 8.4 (Berkeley) 3/20/94 336af9a77bSJohn Marino.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.21 2007/01/09 00:28:04 imp Exp $ 346af9a77bSJohn Marino.\" 35*fdf79913SSascha Wildner.Dd May 5, 2019 366af9a77bSJohn Marino.Dt REGEX 3 376af9a77bSJohn Marino.Os 386af9a77bSJohn Marino.Sh NAME 396af9a77bSJohn Marino.Nm regcomp , 406af9a77bSJohn Marino.Nm regcomp_l , 416af9a77bSJohn Marino.Nm regerror , 426af9a77bSJohn Marino.Nm regexec , 436af9a77bSJohn Marino.Nm regfree , 446af9a77bSJohn Marino.Nm regncomp , 456af9a77bSJohn Marino.Nm regncomp_l , 466af9a77bSJohn Marino.Nm regnexec , 476af9a77bSJohn Marino.Nm regwcomp , 486af9a77bSJohn Marino.Nm regwcomp_l , 49012b8ed8SSascha Wildner.Nm regwexec , 50012b8ed8SSascha Wildner.Nm regwncomp , 51012b8ed8SSascha Wildner.Nm regwncomp_l , 52012b8ed8SSascha Wildner.Nm regwnexec 536af9a77bSJohn Marino.Nd regular-expression library 546d503aa4SSascha Wildner.Sh LIBRARY 556d503aa4SSascha Wildner.Lb libc 566af9a77bSJohn Marino.Sh SYNOPSIS 576af9a77bSJohn Marino.Sy (Standards-compliant APIs) 586af9a77bSJohn Marino.Pp 596af9a77bSJohn Marino.In regex.h 606af9a77bSJohn Marino.Ft int 616af9a77bSJohn Marino.Fo regcomp 626af9a77bSJohn Marino.Fa "regex_t *restrict preg" 636af9a77bSJohn Marino.Fa "const char *restrict pattern" 646af9a77bSJohn Marino.Fa "int cflags" 656af9a77bSJohn Marino.Fc 666af9a77bSJohn Marino.Ft size_t 676af9a77bSJohn Marino.Fo regerror 686af9a77bSJohn Marino.Fa "int errcode" 696af9a77bSJohn Marino.Fa "const regex_t *restrict preg" 706af9a77bSJohn Marino.Fa "char *restrict errbuf" 716af9a77bSJohn Marino.Fa "size_t errbuf_size" 726af9a77bSJohn Marino.Fc 736af9a77bSJohn Marino.Ft int 746af9a77bSJohn Marino.Fo regexec 756af9a77bSJohn Marino.Fa "const regex_t *restrict preg" 766af9a77bSJohn Marino.Fa "const char *restrict string" 776af9a77bSJohn Marino.Fa "size_t nmatch" 786af9a77bSJohn Marino.Fa "regmatch_t pmatch[restrict]" 796af9a77bSJohn Marino.Fa "int eflags" 806af9a77bSJohn Marino.Fc 816af9a77bSJohn Marino.Ft void 826af9a77bSJohn Marino.Fo regfree 836af9a77bSJohn Marino.Fa "regex_t *preg" 846af9a77bSJohn Marino.Fc 856af9a77bSJohn Marino.Pp 866af9a77bSJohn Marino.Sy (Non-portable extensions) 876af9a77bSJohn Marino.Ft int 886af9a77bSJohn Marino.Fo regncomp 896af9a77bSJohn Marino.Fa "regex_t *restrict preg" 906af9a77bSJohn Marino.Fa "const char *restrict pattern" 916af9a77bSJohn Marino.Fa "size_t len" 926af9a77bSJohn Marino.Fa "int cflags" 936af9a77bSJohn Marino.Fc 946af9a77bSJohn Marino.Ft int 956af9a77bSJohn Marino.Fo regnexec 966af9a77bSJohn Marino.Fa "const regex_t *restrict preg" 976af9a77bSJohn Marino.Fa "const char *restrict string" 986af9a77bSJohn Marino.Fa "size_t len" 996af9a77bSJohn Marino.Fa "size_t nmatch" 1006af9a77bSJohn Marino.Fa "regmatch_t pmatch[restrict]" 1016af9a77bSJohn Marino.Fa "int eflags" 1026af9a77bSJohn Marino.Fc 1036af9a77bSJohn Marino.Ft int 1046af9a77bSJohn Marino.Fo regwcomp 1056af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1066af9a77bSJohn Marino.Fa "const wchar_t *restrict widepat" 1076af9a77bSJohn Marino.Fa "int cflags" 1086af9a77bSJohn Marino.Fc 1096af9a77bSJohn Marino.Ft int 1106af9a77bSJohn Marino.Fo regwexec 1116af9a77bSJohn Marino.Fa "const regex_t *restrict preg" 1126af9a77bSJohn Marino.Fa "const wchar_t *restrict widestr" 1136af9a77bSJohn Marino.Fa "size_t nmatch" 1146af9a77bSJohn Marino.Fa "regmatch_t pmatch[restrict]" 1156af9a77bSJohn Marino.Fa "int eflags" 1166af9a77bSJohn Marino.Fc 1176af9a77bSJohn Marino.Ft int 1186af9a77bSJohn Marino.Fo regwncomp 1196af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1206af9a77bSJohn Marino.Fa "const wchar_t *restrict widepat" 1216af9a77bSJohn Marino.Fa "size_t len" 1226af9a77bSJohn Marino.Fa "int cflags" 1236af9a77bSJohn Marino.Fc 1246af9a77bSJohn Marino.Ft int 1256af9a77bSJohn Marino.Fo regwnexec 1266af9a77bSJohn Marino.Fa "const regex_t *restrict preg" 1276af9a77bSJohn Marino.Fa "const wchar_t *restrict widestr" 1286af9a77bSJohn Marino.Fa "size_t len" 1296af9a77bSJohn Marino.Fa "size_t nmatch" 1306af9a77bSJohn Marino.Fa "regmatch_t pmatch[restrict]" 1316af9a77bSJohn Marino.Fa "int eflags" 1326af9a77bSJohn Marino.Fc 1336af9a77bSJohn Marino.In regex.h 1346af9a77bSJohn Marino.In xlocale.h 1356af9a77bSJohn Marino.Ft int 1366af9a77bSJohn Marino.Fo regcomp_l 1376af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1386af9a77bSJohn Marino.Fa "const char *restrict pattern" 1396af9a77bSJohn Marino.Fa "int cflags" 1406af9a77bSJohn Marino.Fa "locale_t restrict" 1416af9a77bSJohn Marino.Fc 1426af9a77bSJohn Marino.Ft int 1436af9a77bSJohn Marino.Fo regncomp_l 1446af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1456af9a77bSJohn Marino.Fa "const char *restrict pattern" 1466af9a77bSJohn Marino.Fa "size_t len" 1476af9a77bSJohn Marino.Fa "int cflags" 1486af9a77bSJohn Marino.Fa "locale_t restrict" 1496af9a77bSJohn Marino.Fc 1506af9a77bSJohn Marino.Ft int 1516af9a77bSJohn Marino.Fo regwcomp_l 1526af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1536af9a77bSJohn Marino.Fa "const wchar_t *restrict widepat" 1546af9a77bSJohn Marino.Fa "int cflags" 1556af9a77bSJohn Marino.Fa "locale_t restrict" 1566af9a77bSJohn Marino.Fc 1576af9a77bSJohn Marino.Ft int 1586af9a77bSJohn Marino.Fo regwncomp_l 1596af9a77bSJohn Marino.Fa "regex_t *restrict preg" 1606af9a77bSJohn Marino.Fa "const wchar_t *restrict widepat" 1616af9a77bSJohn Marino.Fa "size_t len" 1626af9a77bSJohn Marino.Fa "int cflags" 1636af9a77bSJohn Marino.Fa "locale_t restrict" 1646af9a77bSJohn Marino.Fc 1656af9a77bSJohn Marino.Sh DESCRIPTION 1666af9a77bSJohn MarinoThese routines implement 1676af9a77bSJohn Marino.St -p1003.2 1686af9a77bSJohn Marinoregular expressions 1696af9a77bSJohn Marino.Pq Do RE Dc Ns s ; 1706af9a77bSJohn Marinosee 1716af9a77bSJohn Marino.Xr re_format 7 . 1726af9a77bSJohn MarinoThe 1736af9a77bSJohn Marino.Fn regcomp 1746af9a77bSJohn Marinofunction 1756af9a77bSJohn Marinocompiles an RE, written as a string, into an internal form. 1766af9a77bSJohn Marino.Fn regexec 1776af9a77bSJohn Marinomatches that internal form against a string and reports results. 1786af9a77bSJohn Marino.Fn regerror 1796af9a77bSJohn Marinotransforms error codes from either into human-readable messages. 1806af9a77bSJohn Marino.Fn regfree 1816af9a77bSJohn Marinofrees any dynamically-allocated storage used by the internal form 1826af9a77bSJohn Marinoof an RE. 1836af9a77bSJohn Marino.Pp 1846af9a77bSJohn MarinoThe header 1856af9a77bSJohn Marino.In regex.h 1866af9a77bSJohn Marinodeclares two structure types, 1876af9a77bSJohn Marino.Ft regex_t 1886af9a77bSJohn Marinoand 1896af9a77bSJohn Marino.Ft regmatch_t , 1906af9a77bSJohn Marinothe former for compiled internal forms and the latter for match reporting. 1916af9a77bSJohn MarinoIt also declares the four functions, 1926af9a77bSJohn Marinoa type 1936af9a77bSJohn Marino.Ft regoff_t , 1946af9a77bSJohn Marinoand a number of constants with names starting with 1956af9a77bSJohn Marino.Dq Dv REG_ . 1966af9a77bSJohn Marino.Pp 1976af9a77bSJohn MarinoThe 1986af9a77bSJohn Marino.Fn regcomp 1996af9a77bSJohn Marinofunction 2006af9a77bSJohn Marinocompiles the regular expression contained in the 2016af9a77bSJohn Marino.Fa pattern 2026af9a77bSJohn Marinostring, 2036af9a77bSJohn Marinosubject to the flags in 2046af9a77bSJohn Marino.Fa cflags , 2056af9a77bSJohn Marinoand places the results in the 2066af9a77bSJohn Marino.Ft regex_t 2076af9a77bSJohn Marinostructure pointed to by 2086af9a77bSJohn Marino.Fa preg . 2096af9a77bSJohn MarinoThe 2106af9a77bSJohn Marino.Fa cflags 2116af9a77bSJohn Marinoargument 2126af9a77bSJohn Marinois the bitwise OR of zero or more of the following flags: 2136af9a77bSJohn Marino.Bl -tag -width REG_EXTENDED 2146af9a77bSJohn Marino.It Dv REG_EXTENDED 2156af9a77bSJohn MarinoCompile modern 2166af9a77bSJohn Marino.Pq Dq extended 2176af9a77bSJohn MarinoREs, 2186af9a77bSJohn Marinorather than the obsolete 2196af9a77bSJohn Marino.Pq Dq basic 2206af9a77bSJohn MarinoREs that 2216af9a77bSJohn Marinoare the default. 2226af9a77bSJohn Marino.It Dv REG_BASIC 2236af9a77bSJohn MarinoThis is a synonym for 0, 2246af9a77bSJohn Marinoprovided as a counterpart to 2256af9a77bSJohn Marino.Dv REG_EXTENDED 2266af9a77bSJohn Marinoto improve readability. 2276af9a77bSJohn Marino.It Dv REG_NOSPEC 2286af9a77bSJohn MarinoCompile with recognition of all special characters turned off. 2296af9a77bSJohn MarinoAll characters are thus considered ordinary, 2306af9a77bSJohn Marinoso the 2316af9a77bSJohn Marino.Dq RE 2326af9a77bSJohn Marinois a literal string. 2336af9a77bSJohn MarinoThis is an extension, 2346af9a77bSJohn Marinocompatible with but not specified by 2356af9a77bSJohn Marino.St -p1003.2 , 2366af9a77bSJohn Marinoand should be used with 2376af9a77bSJohn Marinocaution in software intended to be portable to other systems. 2386af9a77bSJohn Marino.Dv REG_EXTENDED 2396af9a77bSJohn Marinoand 2406af9a77bSJohn Marino.Dv REG_NOSPEC 2416af9a77bSJohn Marinomay not be used 2426af9a77bSJohn Marinoin the same call to 2436af9a77bSJohn Marino.Fn regcomp . 2446af9a77bSJohn Marino.It Dv REG_LITERAL 2456af9a77bSJohn MarinoAn alias of 2466af9a77bSJohn Marino.Dv REG_NOSPEC . 2476af9a77bSJohn Marino.It Dv REG_ICASE 2486af9a77bSJohn MarinoCompile for matching that ignores upper/lower case distinctions. 2496af9a77bSJohn MarinoSee 2506af9a77bSJohn Marino.Xr re_format 7 . 2516af9a77bSJohn Marino.It Dv REG_NOSUB 2526af9a77bSJohn MarinoCompile for matching that need only report success or failure, 2536af9a77bSJohn Marinonot what was matched. 2546af9a77bSJohn Marino.It Dv REG_NEWLINE 2556af9a77bSJohn MarinoCompile for newline-sensitive matching. 2566af9a77bSJohn MarinoBy default, newline is a completely ordinary character with no special 2576af9a77bSJohn Marinomeaning in either REs or strings. 2586af9a77bSJohn MarinoWith this flag, 2596af9a77bSJohn Marino.Ql [^ 2606af9a77bSJohn Marinobracket expressions and 2616af9a77bSJohn Marino.Ql .\& 2626af9a77bSJohn Marinonever match newline, 2636af9a77bSJohn Marinoa 2646af9a77bSJohn Marino.Ql ^\& 2656af9a77bSJohn Marinoanchor matches the null string after any newline in the string 2666af9a77bSJohn Marinoin addition to its normal function, 2676af9a77bSJohn Marinoand the 2686af9a77bSJohn Marino.Ql $\& 2696af9a77bSJohn Marinoanchor matches the null string before any newline in the 2706af9a77bSJohn Marinostring in addition to its normal function. 2716af9a77bSJohn Marino.It Dv REG_PEND 2726af9a77bSJohn Marino(Note that 2736af9a77bSJohn Marino.Dv REG_PEND 2746af9a77bSJohn Marinois not recognized by any of the wide character or 2756af9a77bSJohn Marino.Dq Nm n 2766af9a77bSJohn Marinovariants. 2776af9a77bSJohn MarinoBesides, the 2786af9a77bSJohn Marino.Dq Nm n 2796af9a77bSJohn Marinovariants can be used instead of 2806af9a77bSJohn Marino.Dv REG_PEND ; 2816af9a77bSJohn Marinosee EXTENDED APIS below.) 2826af9a77bSJohn MarinoThe regular expression ends, 2836af9a77bSJohn Marinonot at the first NUL, 2846af9a77bSJohn Marinobut just before the character pointed to by the 2856af9a77bSJohn Marino.Va re_endp 2866af9a77bSJohn Marinomember of the structure pointed to by 2876af9a77bSJohn Marino.Fa preg . 2886af9a77bSJohn MarinoThe 2896af9a77bSJohn Marino.Va re_endp 2906af9a77bSJohn Marinomember is of type 2916af9a77bSJohn Marino.Ft "const char *" . 2926af9a77bSJohn MarinoThis flag permits inclusion of NULs in the RE; 2936af9a77bSJohn Marinothey are considered ordinary characters. 2946af9a77bSJohn MarinoThis is an extension, 2956af9a77bSJohn Marinocompatible with but not specified by 2966af9a77bSJohn Marino.St -p1003.2 , 2976af9a77bSJohn Marinoand should be used with 2986af9a77bSJohn Marinocaution in software intended to be portable to other systems. 2996af9a77bSJohn Marino.It Dv REG_ENHANCED 3006af9a77bSJohn MarinoRecognized enhanced regular expression features; see 3016af9a77bSJohn Marino.Xr re_format 7 3026af9a77bSJohn Marinofor details. 3036af9a77bSJohn MarinoThis is an extension not specified by 3046af9a77bSJohn Marino.St -p1003.2 , 3056af9a77bSJohn Marinoand should be used with 3066af9a77bSJohn Marinocaution in software intended to be portable to other systems. 3076af9a77bSJohn Marino.It Dv REG_MINIMAL 3086af9a77bSJohn MarinoUse minimal (non-greedy) repetitions instead of the normal greedy ones; see 3096af9a77bSJohn Marino.Xr re_format 7 3106af9a77bSJohn Marinofor details. 3116af9a77bSJohn Marino(This only applies when both 3126af9a77bSJohn Marino.Dv REG_ENHANCED 3136af9a77bSJohn Marinoand 3146af9a77bSJohn Marino.Dv REG_EXTENDED 3156af9a77bSJohn Marinoare also set.) 3166af9a77bSJohn MarinoThis is an extension not specified by 3176af9a77bSJohn Marino.St -p1003.2 , 3186af9a77bSJohn Marinoand should be used with 3196af9a77bSJohn Marinocaution in software intended to be portable to other systems. 3206af9a77bSJohn Marino.It Dv REG_UNGREEDY 3216af9a77bSJohn MarinoAlias of 3226af9a77bSJohn Marino.Dv REG_MINIMAL . 3236af9a77bSJohn Marino.El 3246af9a77bSJohn Marino.Pp 3256af9a77bSJohn MarinoWhen successful, 3266af9a77bSJohn Marino.Fn regcomp 3276af9a77bSJohn Marinoreturns 0 and fills in the structure pointed to by 3286af9a77bSJohn Marino.Fa preg . 3296af9a77bSJohn MarinoOne member of that structure 3306af9a77bSJohn Marino(other than 3316af9a77bSJohn Marino.Va re_endp ) 3326af9a77bSJohn Marinois publicized: 3336af9a77bSJohn Marino.Va re_nsub , 3346af9a77bSJohn Marinoof type 3356af9a77bSJohn Marino.Ft size_t , 3366af9a77bSJohn Marinocontains the number of parenthesized subexpressions within the RE 3376af9a77bSJohn Marino(except that the value of this member is undefined if the 3386af9a77bSJohn Marino.Dv REG_NOSUB 3396af9a77bSJohn Marinoflag was used). 3406af9a77bSJohn MarinoIf 3416af9a77bSJohn Marino.Fn regcomp 3426af9a77bSJohn Marinofails, it returns a non-zero error code; 3436af9a77bSJohn Marinosee 344*fdf79913SSascha Wildner.Sx RETURN VALUES . 3456af9a77bSJohn Marino.Pp 3466af9a77bSJohn MarinoThe 3476af9a77bSJohn Marino.Fn regexec 3486af9a77bSJohn Marinofunction 3496af9a77bSJohn Marinomatches the compiled RE pointed to by 3506af9a77bSJohn Marino.Fa preg 3516af9a77bSJohn Marinoagainst the 3526af9a77bSJohn Marino.Fa string , 3536af9a77bSJohn Marinosubject to the flags in 3546af9a77bSJohn Marino.Fa eflags , 3556af9a77bSJohn Marinoand reports results using 3566af9a77bSJohn Marino.Fa nmatch , 3576af9a77bSJohn Marino.Fa pmatch , 3586af9a77bSJohn Marinoand the returned value. 3596af9a77bSJohn MarinoThe RE must have been compiled by a previous invocation of 3606af9a77bSJohn Marino.Fn regcomp . 3616af9a77bSJohn MarinoThe compiled form is not altered during execution of 3626af9a77bSJohn Marino.Fn regexec , 3636af9a77bSJohn Marinoso a single compiled RE can be used simultaneously by multiple threads. 3646af9a77bSJohn Marino.Pp 3656af9a77bSJohn MarinoBy default, 3666af9a77bSJohn Marinothe NUL-terminated string pointed to by 3676af9a77bSJohn Marino.Fa string 3686af9a77bSJohn Marinois considered to be the text of an entire line, minus any terminating 3696af9a77bSJohn Marinonewline. 3706af9a77bSJohn MarinoThe 3716af9a77bSJohn Marino.Fa eflags 3726af9a77bSJohn Marinoargument is the bitwise OR of zero or more of the following flags: 3736af9a77bSJohn Marino.Bl -tag -width REG_STARTEND 3746af9a77bSJohn Marino.It Dv REG_NOTBOL 3756af9a77bSJohn MarinoThe first character of 3766af9a77bSJohn Marinothe string 3776af9a77bSJohn Marinois not the beginning of a line, so the 3786af9a77bSJohn Marino.Ql ^\& 3796af9a77bSJohn Marinoanchor should not match before it. 3806af9a77bSJohn MarinoThis does not affect the behavior of newlines under 3816af9a77bSJohn Marino.Dv REG_NEWLINE . 3826af9a77bSJohn Marino.It Dv REG_NOTEOL 3836af9a77bSJohn MarinoThe NUL terminating 3846af9a77bSJohn Marinothe string 3856af9a77bSJohn Marinodoes not end a line, so the 3866af9a77bSJohn Marino.Ql $\& 3876af9a77bSJohn Marinoanchor should not match before it. 3886af9a77bSJohn MarinoThis does not affect the behavior of newlines under 3896af9a77bSJohn Marino.Dv REG_NEWLINE . 3906af9a77bSJohn Marino.It Dv REG_STARTEND 3916af9a77bSJohn MarinoThe string is considered to start at 3926af9a77bSJohn Marino.Fa string 3936af9a77bSJohn Marino+ 3946af9a77bSJohn Marino.Fa pmatch Ns [0]. Ns Va rm_so 3956af9a77bSJohn Marinoand to have a terminating NUL located at 3966af9a77bSJohn Marino.Fa string 3976af9a77bSJohn Marino+ 3986af9a77bSJohn Marino.Fa pmatch Ns [0]. Ns Va rm_eo 3996af9a77bSJohn Marino(there need not actually be a NUL at that location), 4006af9a77bSJohn Marinoregardless of the value of 4016af9a77bSJohn Marino.Fa nmatch . 4026af9a77bSJohn MarinoSee below for the definition of 4036af9a77bSJohn Marino.Fa pmatch 4046af9a77bSJohn Marinoand 4056af9a77bSJohn Marino.Fa nmatch . 4066af9a77bSJohn MarinoThis is an extension, 4076af9a77bSJohn Marinocompatible with but not specified by 4086af9a77bSJohn Marino.St -p1003.2 , 4096af9a77bSJohn Marinoand should be used with 4106af9a77bSJohn Marinocaution in software intended to be portable to other systems. 4116af9a77bSJohn MarinoNote that a non-zero 4126af9a77bSJohn Marino.Va rm_so 4136af9a77bSJohn Marinodoes not imply 4146af9a77bSJohn Marino.Dv REG_NOTBOL ; 4156af9a77bSJohn Marino.Dv REG_STARTEND 4166af9a77bSJohn Marinoaffects only the location of the string, 4176af9a77bSJohn Marinonot how it is matched. 4186af9a77bSJohn Marino.El 4196af9a77bSJohn Marino.Pp 4206af9a77bSJohn MarinoSee 4216af9a77bSJohn Marino.Xr re_format 7 4226af9a77bSJohn Marinofor a discussion of what is matched in situations where an RE or a 4236af9a77bSJohn Marinoportion thereof could match any of several substrings of 4246af9a77bSJohn Marino.Fa string . 4256af9a77bSJohn Marino.Pp 4266af9a77bSJohn MarinoNormally, 4276af9a77bSJohn Marino.Fn regexec 4286af9a77bSJohn Marinoreturns 0 for success and the non-zero code 4296af9a77bSJohn Marino.Dv REG_NOMATCH 4306af9a77bSJohn Marinofor failure. 4316af9a77bSJohn MarinoOther non-zero error codes may be returned in exceptional situations; 4326af9a77bSJohn Marinosee 433*fdf79913SSascha Wildner.Sx RETURN VALUES . 4346af9a77bSJohn Marino.Pp 4356af9a77bSJohn MarinoIf 4366af9a77bSJohn Marino.Dv REG_NOSUB 4376af9a77bSJohn Marinowas specified in the compilation of the RE, 4386af9a77bSJohn Marinoor if 4396af9a77bSJohn Marino.Fa nmatch 4406af9a77bSJohn Marinois 0, 4416af9a77bSJohn Marino.Fn regexec 4426af9a77bSJohn Marinoignores the 4436af9a77bSJohn Marino.Fa pmatch 4446af9a77bSJohn Marinoargument (but see below for the case where 4456af9a77bSJohn Marino.Dv REG_STARTEND 4466af9a77bSJohn Marinois specified). 4476af9a77bSJohn MarinoOtherwise, 4486af9a77bSJohn Marino.Fa pmatch 4496af9a77bSJohn Marinopoints to an array of 4506af9a77bSJohn Marino.Fa nmatch 4516af9a77bSJohn Marinostructures of type 4526af9a77bSJohn Marino.Ft regmatch_t . 4536af9a77bSJohn MarinoSuch a structure has at least the members 4546af9a77bSJohn Marino.Va rm_so 4556af9a77bSJohn Marinoand 4566af9a77bSJohn Marino.Va rm_eo , 4576af9a77bSJohn Marinoboth of type 4586af9a77bSJohn Marino.Ft regoff_t 4596af9a77bSJohn Marino(a signed arithmetic type at least as large as an 4606af9a77bSJohn Marino.Ft off_t 4616af9a77bSJohn Marinoand a 4626af9a77bSJohn Marino.Ft ssize_t ) , 4636af9a77bSJohn Marinocontaining respectively the offset of the first character of a substring 4646af9a77bSJohn Marinoand the offset of the first character after the end of the substring. 4656af9a77bSJohn MarinoOffsets are measured from the beginning of the 4666af9a77bSJohn Marino.Fa string 4676af9a77bSJohn Marinoargument given to 4686af9a77bSJohn Marino.Fn regexec . 4696af9a77bSJohn MarinoAn empty substring is denoted by equal offsets, 4706af9a77bSJohn Marinoboth indicating the character following the empty substring. 4716af9a77bSJohn Marino.Pp 4726af9a77bSJohn MarinoThe 0th member of the 4736af9a77bSJohn Marino.Fa pmatch 4746af9a77bSJohn Marinoarray is filled in to indicate what substring of 4756af9a77bSJohn Marino.Fa string 4766af9a77bSJohn Marinowas matched by the entire RE. 4776af9a77bSJohn MarinoRemaining members report what substring was matched by parenthesized 4786af9a77bSJohn Marinosubexpressions within the RE; 4796af9a77bSJohn Marinomember 4806af9a77bSJohn Marino.Va i 4816af9a77bSJohn Marinoreports subexpression 4826af9a77bSJohn Marino.Va i , 4836af9a77bSJohn Marinowith subexpressions counted (starting at 1) by the order of their opening 4846af9a77bSJohn Marinoparentheses in the RE, left to right. 4856af9a77bSJohn MarinoUnused entries in the array (corresponding either to subexpressions that 4866af9a77bSJohn Marinodid not participate in the match at all, or to subexpressions that do not 4876af9a77bSJohn Marinoexist in the RE (that is, 4886af9a77bSJohn Marino.Va i 4896af9a77bSJohn Marino> 4906af9a77bSJohn Marino.Fa preg Ns -> Ns Va re_nsub ) ) 4916af9a77bSJohn Marinohave both 4926af9a77bSJohn Marino.Va rm_so 4936af9a77bSJohn Marinoand 4946af9a77bSJohn Marino.Va rm_eo 4956af9a77bSJohn Marinoset to -1. 4966af9a77bSJohn MarinoIf a subexpression participated in the match several times, 4976af9a77bSJohn Marinothe reported substring is the last one it matched. 4986af9a77bSJohn Marino(Note, as an example in particular, that when the RE 4996af9a77bSJohn Marino.Ql "(b*)+" 5006af9a77bSJohn Marinomatches 5016af9a77bSJohn Marino.Ql bbb , 5026af9a77bSJohn Marinothe parenthesized subexpression matches each of the three 5036af9a77bSJohn Marino.So Li b Sc Ns s 5046af9a77bSJohn Marinoand then 5056af9a77bSJohn Marinoan infinite number of empty strings following the last 5066af9a77bSJohn Marino.Ql b , 5076af9a77bSJohn Marinoso the reported substring is one of the empties.) 5086af9a77bSJohn Marino.Pp 5096af9a77bSJohn MarinoIf 5106af9a77bSJohn Marino.Dv REG_STARTEND 5116af9a77bSJohn Marinois specified, 5126af9a77bSJohn Marino.Fa pmatch 5136af9a77bSJohn Marinomust point to at least one 5146af9a77bSJohn Marino.Ft regmatch_t 5156af9a77bSJohn Marino(even if 5166af9a77bSJohn Marino.Fa nmatch 5176af9a77bSJohn Marinois 0 or 5186af9a77bSJohn Marino.Dv REG_NOSUB 5196af9a77bSJohn Marinowas specified), 5206af9a77bSJohn Marinoto hold the input offsets for 5216af9a77bSJohn Marino.Dv REG_STARTEND . 5226af9a77bSJohn MarinoUse for output is still entirely controlled by 5236af9a77bSJohn Marino.Fa nmatch ; 5246af9a77bSJohn Marinoif 5256af9a77bSJohn Marino.Fa nmatch 5266af9a77bSJohn Marinois 0 or 5276af9a77bSJohn Marino.Dv REG_NOSUB 5286af9a77bSJohn Marinowas specified, 5296af9a77bSJohn Marinothe value of 5306af9a77bSJohn Marino.Fa pmatch Ns [0] 5316af9a77bSJohn Marinowill not be changed by a successful 5326af9a77bSJohn Marino.Fn regexec . 5336af9a77bSJohn Marino.Pp 5346af9a77bSJohn MarinoThe 5356af9a77bSJohn Marino.Fn regerror 5366af9a77bSJohn Marinofunction 5376af9a77bSJohn Marinomaps a non-zero 5386af9a77bSJohn Marino.Fa errcode 5396af9a77bSJohn Marinofrom either 5406af9a77bSJohn Marino.Fn regcomp 5416af9a77bSJohn Marinoor 5426af9a77bSJohn Marino.Fn regexec 5436af9a77bSJohn Marinoto a human-readable, printable message. 5446af9a77bSJohn MarinoIf 5456af9a77bSJohn Marino.Fa preg 5466af9a77bSJohn Marinois 5476af9a77bSJohn Marino.No non\- Ns Dv NULL , 5486af9a77bSJohn Marinothe error code should have arisen from use of 5496af9a77bSJohn Marinothe 5506af9a77bSJohn Marino.Ft regex_t 5516af9a77bSJohn Marinopointed to by 5526af9a77bSJohn Marino.Fa preg , 5536af9a77bSJohn Marinoand if the error code came from 5546af9a77bSJohn Marino.Fn regcomp , 5556af9a77bSJohn Marinoit should have been the result from the most recent 5566af9a77bSJohn Marino.Fn regcomp 5576af9a77bSJohn Marinousing that 5586af9a77bSJohn Marino.Ft regex_t . 5596af9a77bSJohn MarinoThe 5606af9a77bSJohn Marino.Fn ( regerror 5616af9a77bSJohn Marinomay be able to supply a more detailed message using information 5626af9a77bSJohn Marinofrom the 5636af9a77bSJohn Marino.Ft regex_t . ) 5646af9a77bSJohn MarinoThe 5656af9a77bSJohn Marino.Fn regerror 5666af9a77bSJohn Marinofunction 5676af9a77bSJohn Marinoplaces the NUL-terminated message into the buffer pointed to by 5686af9a77bSJohn Marino.Fa errbuf , 5696af9a77bSJohn Marinolimiting the length (including the NUL) to at most 5706af9a77bSJohn Marino.Fa errbuf_size 5716af9a77bSJohn Marinobytes. 5726af9a77bSJohn MarinoIf the whole message will not fit, 5736af9a77bSJohn Marinoas much of it as will fit before the terminating NUL is supplied. 5746af9a77bSJohn MarinoIn any case, 5756af9a77bSJohn Marinothe returned value is the size of buffer needed to hold the whole 5766af9a77bSJohn Marinomessage (including terminating NUL). 5776af9a77bSJohn MarinoIf 5786af9a77bSJohn Marino.Fa errbuf_size 5796af9a77bSJohn Marinois 0, 5806af9a77bSJohn Marino.Fa errbuf 5816af9a77bSJohn Marinois ignored but the return value is still correct. 5826af9a77bSJohn Marino.Pp 5836af9a77bSJohn MarinoIf the 5846af9a77bSJohn Marino.Fa errcode 5856af9a77bSJohn Marinogiven to 5866af9a77bSJohn Marino.Fn regerror 5876af9a77bSJohn Marinois first ORed with 5886af9a77bSJohn Marino.Dv REG_ITOA , 5896af9a77bSJohn Marinothe 5906af9a77bSJohn Marino.Dq message 5916af9a77bSJohn Marinothat results is the printable name of the error code, 5926af9a77bSJohn Marinoe.g.\& 5936af9a77bSJohn Marino.Dq Dv REG_NOMATCH , 5946af9a77bSJohn Marinorather than an explanation thereof. 5956af9a77bSJohn MarinoIf 5966af9a77bSJohn Marino.Fa errcode 5976af9a77bSJohn Marinois 5986af9a77bSJohn Marino.Dv REG_ATOI , 5996af9a77bSJohn Marinothen 6006af9a77bSJohn Marino.Fa preg 6016af9a77bSJohn Marinoshall be 6026af9a77bSJohn Marino.No non\- Ns Dv NULL 6036af9a77bSJohn Marinoand the 6046af9a77bSJohn Marino.Va re_endp 6056af9a77bSJohn Marinomember of the structure it points to 6066af9a77bSJohn Marinomust point to the printable name of an error code; 6076af9a77bSJohn Marinoin this case, the result in 6086af9a77bSJohn Marino.Fa errbuf 6096af9a77bSJohn Marinois the decimal digits of 6106af9a77bSJohn Marinothe numeric value of the error code 6116af9a77bSJohn Marino(0 if the name is not recognized). 6126af9a77bSJohn Marino.Dv REG_ITOA 6136af9a77bSJohn Marinoand 6146af9a77bSJohn Marino.Dv REG_ATOI 6156af9a77bSJohn Marinoare intended primarily as debugging facilities; 6166af9a77bSJohn Marinothey are extensions, 6176af9a77bSJohn Marinocompatible with but not specified by 6186af9a77bSJohn Marino.St -p1003.2 , 6196af9a77bSJohn Marinoand should be used with 6206af9a77bSJohn Marinocaution in software intended to be portable to other systems. 6216af9a77bSJohn MarinoBe warned also that they are considered experimental and changes are possible. 6226af9a77bSJohn Marino.Pp 6236af9a77bSJohn MarinoThe 6246af9a77bSJohn Marino.Fn regfree 6256af9a77bSJohn Marinofunction 6266af9a77bSJohn Marinofrees any dynamically-allocated storage associated with the compiled RE 6276af9a77bSJohn Marinopointed to by 6286af9a77bSJohn Marino.Fa preg . 6296af9a77bSJohn MarinoThe remaining 6306af9a77bSJohn Marino.Ft regex_t 6316af9a77bSJohn Marinois no longer a valid compiled RE 6326af9a77bSJohn Marinoand the effect of supplying it to 6336af9a77bSJohn Marino.Fn regexec 6346af9a77bSJohn Marinoor 6356af9a77bSJohn Marino.Fn regerror 6366af9a77bSJohn Marinois undefined. 6376af9a77bSJohn Marino.Pp 6386af9a77bSJohn MarinoNone of these functions references global variables except for tables 6396af9a77bSJohn Marinoof constants; 6406af9a77bSJohn Marinoall are safe for use from multiple threads if the arguments are safe. 6416af9a77bSJohn Marino.Sh EXTENDED APIS 6426af9a77bSJohn MarinoThese extended APIs are available in Mac OS X 10.8 and beyond, when the 6436af9a77bSJohn Marinodeployment target is 10.8 or later. 6446af9a77bSJohn MarinoIt should also be noted that any of the 6456af9a77bSJohn Marino.Fn regcomp 6466af9a77bSJohn Marinovariants may be used to initialize a 6476af9a77bSJohn Marino.Ft regex_t 6486af9a77bSJohn Marinostructure, that can then be passed to any of the 6496af9a77bSJohn Marino.Fn regexec 6506af9a77bSJohn Marinovariants. 6516af9a77bSJohn MarinoSo it is quite legal to compile a wide character RE and use it to match a 6526af9a77bSJohn Marinomultibyte character string, or vice versa. 6536af9a77bSJohn Marino.Pp 6546af9a77bSJohn MarinoThe 6556af9a77bSJohn Marino.Fn regncomp 6566af9a77bSJohn Marinoroutine compiles regular expressions like 6576af9a77bSJohn Marino.Fn regcomp , 6586af9a77bSJohn Marinobut the length of the regular expression string is specified, allowing a string 6596af9a77bSJohn Marinothat is not NUL terminated and/or contains NUL characters. 6606af9a77bSJohn MarinoThis is a modern replacement for using 6616af9a77bSJohn Marino.Fn regcomp 6626af9a77bSJohn Marinowith the 6636af9a77bSJohn Marino.Dv REG_PEND 6646af9a77bSJohn Marinooption. 6656af9a77bSJohn Marino.Pp 6666af9a77bSJohn MarinoSimilarly, the 6676af9a77bSJohn Marino.Fn regnexec 6686af9a77bSJohn Marinoroutine is like 6696af9a77bSJohn Marino.Fn regexec , 6706af9a77bSJohn Marinobut the length of the string to match is specified, allowing a string 6716af9a77bSJohn Marinothat is not NUL terminated and/or contains NUL characters. 6726af9a77bSJohn Marino.Pp 6736af9a77bSJohn MarinoThe 6746af9a77bSJohn Marino.Fn regwcomp 6756af9a77bSJohn Marinoand 6766af9a77bSJohn Marino.Fn regwexec 6776af9a77bSJohn Marinovariants take a wide-character 6786af9a77bSJohn Marino.Vt ( wchar_t ) 6796af9a77bSJohn Marinostring for the regular expression and string to match. 6806af9a77bSJohn MarinoAnd 6816af9a77bSJohn Marino.Fn regwncomp 6826af9a77bSJohn Marinoand 6836af9a77bSJohn Marino.Fn regwnexec 6846af9a77bSJohn Marinoare variants that allow specifying the wide character string length, and 6856af9a77bSJohn Marinoso allows wide character strings that are not NUL terminated and/or 6866af9a77bSJohn Marinocontains NUL characters. 6876af9a77bSJohn Marino.Sh INTERACTION WITH THE LOCALE 6886af9a77bSJohn MarinoWhen 6896af9a77bSJohn Marino.Fn regcomp 6906af9a77bSJohn Marinoor one of its variants is run, the regular expression is compiled into an 6916af9a77bSJohn Marinointernal form, which may include specific information about the locale currently 6926af9a77bSJohn Marinoin effect, such as equivalence classes or multi-character collation symbols. 6936af9a77bSJohn MarinoSo a reference to the current locale is also stored with the internal form, 6946af9a77bSJohn Marinoso that when 6956af9a77bSJohn Marino.Fn regexec 6966af9a77bSJohn Marinois run, it can use the same locale (even if the locale is changed in-between 6976af9a77bSJohn Marinothe calls to 6986af9a77bSJohn Marino.Fn regcomp 6996af9a77bSJohn Marinoand 7006af9a77bSJohn Marino.Fn regexec ) . 7016af9a77bSJohn Marino.Pp 7026af9a77bSJohn MarinoTo provide more direct control over which locale is used, 7036af9a77bSJohn Marinoroutines with 7046af9a77bSJohn Marino.Dq Nm _l 7056af9a77bSJohn Marinoappended to their names are provided that work just like the variants 7066af9a77bSJohn Marinowithout the 7076af9a77bSJohn Marino.Dq Nm _l , 7086af9a77bSJohn Marinoexcept that a locale (via a 7096af9a77bSJohn Marino.Vt locale_t 7106af9a77bSJohn Marinovariable type) is specified directly. 7116af9a77bSJohn MarinoNote that only variants of 7126af9a77bSJohn Marino.Fn regcomp 7136af9a77bSJohn Marinohave 7146af9a77bSJohn Marino.Dq Nm _l 7156af9a77bSJohn Marinovariants, since the 7166af9a77bSJohn Marino.Fn regexec 7176af9a77bSJohn Marinovariants just use the reference to the locale stored in the internal form. 7186af9a77bSJohn Marino.Sh IMPLEMENTATION CHOICES 7196af9a77bSJohn MarinoThe 7206af9a77bSJohn Marino.Nm regex 7216af9a77bSJohn Marinoimplementation in Mac OS X 10.8 and later is based on a heavily modified subset 7226af9a77bSJohn Marinoof TRE (http://laurikari.net/tre/). 7236af9a77bSJohn MarinoThis provides improved performance, better conformance and additional features. 7246af9a77bSJohn MarinoHowever, both API and binary compatibility have been maintained with previous 7256af9a77bSJohn Marinoreleases, so binaries 7266af9a77bSJohn Marinobuilt on previous releases should work on 10.8 and later, and binaries built on 7276af9a77bSJohn Marino10.8 and later should be able to run on previous releases (as long as none of 7286af9a77bSJohn Marinothe new variants or new features are used. 7296af9a77bSJohn Marino.Pp 7306af9a77bSJohn MarinoThere are a number of decisions that 7316af9a77bSJohn Marino.St -p1003.2 7326af9a77bSJohn Marinoleaves up to the implementor, 7336af9a77bSJohn Marinoeither by explicitly saying 7346af9a77bSJohn Marino.Dq undefined 7356af9a77bSJohn Marinoor by virtue of them being 7366af9a77bSJohn Marinoforbidden by the RE grammar. 7376af9a77bSJohn MarinoThis implementation treats them as follows. 7386af9a77bSJohn Marino.Pp 7396af9a77bSJohn MarinoSee 7406af9a77bSJohn Marino.Xr re_format 7 7416af9a77bSJohn Marinofor a discussion of the definition of case-independent matching. 7426af9a77bSJohn Marino.Pp 7436af9a77bSJohn MarinoThere is no particular limit on the length of REs, 7446af9a77bSJohn Marinoexcept insofar as memory is limited. 7456af9a77bSJohn MarinoMemory usage is approximately linear in RE size, and largely insensitive 7466af9a77bSJohn Marinoto RE complexity, except for bounded repetitions. 7476af9a77bSJohn MarinoSee 7486af9a77bSJohn Marino.Sx BUGS 7496af9a77bSJohn Marinofor one short RE using them 7506af9a77bSJohn Marinothat will run almost any system out of memory. 7516af9a77bSJohn Marino.Pp 7526af9a77bSJohn MarinoA backslashed character other than one specifically given a magic meaning 7536af9a77bSJohn Marinoby 7546af9a77bSJohn Marino.St -p1003.2 7556af9a77bSJohn Marino(such magic meanings occur only in obsolete 7566af9a77bSJohn Marino.Bq Dq basic 7576af9a77bSJohn MarinoREs) 7586af9a77bSJohn Marinois taken as an ordinary character. 7596af9a77bSJohn Marino.Pp 7606af9a77bSJohn MarinoAny unmatched 7616af9a77bSJohn Marino.Ql [\& 7626af9a77bSJohn Marinois a 7636af9a77bSJohn Marino.Dv REG_EBRACK 7646af9a77bSJohn Marinoerror. 7656af9a77bSJohn Marino.Pp 7666af9a77bSJohn MarinoEquivalence classes cannot begin or end bracket-expression ranges. 7676af9a77bSJohn MarinoThe endpoint of one range cannot begin another. 7686af9a77bSJohn Marino.Pp 7696af9a77bSJohn Marino.Dv RE_DUP_MAX , 7706af9a77bSJohn Marinothe limit on repetition counts in bounded repetitions, is 255. 7716af9a77bSJohn Marino.Pp 7726af9a77bSJohn MarinoA repetition operator 7736af9a77bSJohn Marino.Ql ( ?\& , 7746af9a77bSJohn Marino.Ql *\& , 7756af9a77bSJohn Marino.Ql +\& , 7766af9a77bSJohn Marinoor bounds) 7776af9a77bSJohn Marinocannot follow another 7786af9a77bSJohn Marinorepetition operator, except for the use of 7796af9a77bSJohn Marino.Ql ?\& 7806af9a77bSJohn Marinofor minimal repetition (for enhanced extended REs; see 7816af9a77bSJohn Marino.Xr re_format 7 7826af9a77bSJohn Marinofor details). 7836af9a77bSJohn MarinoA repetition operator cannot begin an expression or subexpression 7846af9a77bSJohn Marinoor follow 7856af9a77bSJohn Marino.Ql ^\& 7866af9a77bSJohn Marinoor 7876af9a77bSJohn Marino.Ql |\& . 7886af9a77bSJohn Marino.Pp 7896af9a77bSJohn Marino.Ql |\& 7906af9a77bSJohn Marinocannot appear first or last in a (sub)expression or after another 7916af9a77bSJohn Marino.Ql |\& , 7926af9a77bSJohn Marinoi.e., an operand of 7936af9a77bSJohn Marino.Ql |\& 7946af9a77bSJohn Marinocannot be an empty subexpression. 7956af9a77bSJohn MarinoAn empty parenthesized subexpression, 7966af9a77bSJohn Marino.Ql "()" , 7976af9a77bSJohn Marinois legal and matches an 7986af9a77bSJohn Marinoempty (sub)string. 7996af9a77bSJohn MarinoAn empty string is not a legal RE. 8006af9a77bSJohn Marino.Pp 8016af9a77bSJohn MarinoA 8026af9a77bSJohn Marino.Ql {\& 8036af9a77bSJohn Marinofollowed by a digit is considered the beginning of bounds for a 8046af9a77bSJohn Marinobounded repetition, which must then follow the syntax for bounds. 8056af9a77bSJohn MarinoA 8066af9a77bSJohn Marino.Ql {\& 8076af9a77bSJohn Marino.Em not 8086af9a77bSJohn Marinofollowed by a digit is considered an ordinary character. 8096af9a77bSJohn Marino.Pp 8106af9a77bSJohn Marino.Ql ^\& 8116af9a77bSJohn Marinoand 8126af9a77bSJohn Marino.Ql $\& 8136af9a77bSJohn Marinobeginning and ending subexpressions in obsolete 8146af9a77bSJohn Marino.Pq Dq basic 8156af9a77bSJohn MarinoREs are anchors, not ordinary characters. 816*fdf79913SSascha Wildner.Sh RETURN VALUES 8176af9a77bSJohn MarinoNon-zero error codes from 8186af9a77bSJohn Marino.Fn regcomp 8196af9a77bSJohn Marinoand 8206af9a77bSJohn Marino.Fn regexec 8216af9a77bSJohn Marinoinclude the following: 8226af9a77bSJohn Marino.Pp 8236af9a77bSJohn Marino.Bl -tag -width REG_ECOLLATE -compact 8246af9a77bSJohn Marino.It Dv REG_NOMATCH 8256af9a77bSJohn MarinoThe 8266af9a77bSJohn Marino.Fn regexec 8276af9a77bSJohn Marinofunction 8286af9a77bSJohn Marinofailed to match 8296af9a77bSJohn Marino.It Dv REG_BADPAT 8306af9a77bSJohn Marinoinvalid regular expression 8316af9a77bSJohn Marino.It Dv REG_ECOLLATE 8326af9a77bSJohn Marinoinvalid collating element 8336af9a77bSJohn Marino.It Dv REG_ECTYPE 8346af9a77bSJohn Marinoinvalid character class 8356af9a77bSJohn Marino.It Dv REG_EESCAPE 8366af9a77bSJohn Marino.Ql \e 8376af9a77bSJohn Marinoapplied to unescapable character 8386af9a77bSJohn Marino.It Dv REG_ESUBREG 8396af9a77bSJohn Marinoinvalid backreference number 8406af9a77bSJohn Marino.It Dv REG_EBRACK 8416af9a77bSJohn Marinobrackets 8426af9a77bSJohn Marino.Ql "[ ]" 8436af9a77bSJohn Marinonot balanced 8446af9a77bSJohn Marino.It Dv REG_EPAREN 8456af9a77bSJohn Marinoparentheses 8466af9a77bSJohn Marino.Ql "( )" 8476af9a77bSJohn Marinonot balanced 8486af9a77bSJohn Marino.It Dv REG_EBRACE 8496af9a77bSJohn Marinobraces 8506af9a77bSJohn Marino.Ql "{ }" 8516af9a77bSJohn Marinonot balanced 8526af9a77bSJohn Marino.It Dv REG_BADBR 8536af9a77bSJohn Marinoinvalid repetition count(s) in 8546af9a77bSJohn Marino.Ql "{ }" 8556af9a77bSJohn Marino.It Dv REG_ERANGE 8566af9a77bSJohn Marinoinvalid character range in 8576af9a77bSJohn Marino.Ql "[ ]" 8586af9a77bSJohn Marino.It Dv REG_ESPACE 8596af9a77bSJohn Marinoran out of memory 8606af9a77bSJohn Marino.It Dv REG_BADRPT 8616af9a77bSJohn Marino.Ql ?\& , 8626af9a77bSJohn Marino.Ql *\& , 8636af9a77bSJohn Marinoor 8646af9a77bSJohn Marino.Ql +\& 8656af9a77bSJohn Marinooperand invalid 8666af9a77bSJohn Marino.It Dv REG_EMPTY 8676af9a77bSJohn Marinoempty (sub)expression 8686af9a77bSJohn Marino.It Dv REG_ASSERT 8696af9a77bSJohn Marinocannot happen - you found a bug 8706af9a77bSJohn Marino.It Dv REG_INVARG 8716af9a77bSJohn Marinoinvalid argument, e.g.\& negative-length string 8726af9a77bSJohn Marino.It Dv REG_ILLSEQ 8736af9a77bSJohn Marinoillegal byte sequence (bad multibyte character) 8746af9a77bSJohn Marino.El 8756af9a77bSJohn Marino.Sh SEE ALSO 8766af9a77bSJohn Marino.Xr grep 1 , 8776af9a77bSJohn Marino.Xr re_format 7 8786af9a77bSJohn Marino.Pp 8796af9a77bSJohn Marino.St -p1003.2 , 8806af9a77bSJohn Marinosections 2.8 (Regular Expression Notation) 8816af9a77bSJohn Marinoand 8826af9a77bSJohn MarinoB.5 (C Binding for Regular Expression Matching). 8836af9a77bSJohn Marino.Sh HISTORY 8846af9a77bSJohn MarinoThe 8856af9a77bSJohn Marino.Nm regex 8866af9a77bSJohn Marinoimplementation is based on a heavily modified subset of TRE 8876af9a77bSJohn Marino(http://laurikari.net/tre/), originally written by Ville Laurikari. 8886af9a77bSJohn MarinoPrevious releases used an implementation originally written by 8896af9a77bSJohn Marino.An Henry Spencer , 8906af9a77bSJohn Marinoand altered for inclusion in the 8916af9a77bSJohn Marino.Bx 4.4 8926af9a77bSJohn Marinodistribution. 8936af9a77bSJohn Marino.Sh BUGS 8946af9a77bSJohn MarinoThe beginning-of-line and end-of-line anchors ( 8956af9a77bSJohn Marino.Dq ^\& 8966af9a77bSJohn Marinoand 8976af9a77bSJohn Marino.Dq $\& ) 8986af9a77bSJohn Marinoare currently implemented so that repetitions can not be applied to them. 8996af9a77bSJohn MarinoThe standards are unclear about whether this is legal, but other 9006af9a77bSJohn Marino.Nm regex 9016af9a77bSJohn Marinopackages do support this case. 9026af9a77bSJohn MarinoIt is best to avoid this non-portable (and not really very useful) case. 9036af9a77bSJohn Marino.Pp 9046af9a77bSJohn MarinoThe back-reference code is subtle and doubts linger about its correctness 9056af9a77bSJohn Marinoin complex cases. 9066af9a77bSJohn Marino.Pp 9076af9a77bSJohn MarinoThe 9086af9a77bSJohn Marino.Fn regexec 9096af9a77bSJohn Marinovariants use one of two internal matching engines. 9106af9a77bSJohn MarinoThe normal one is linear worst-case time in the length of the text being 9116af9a77bSJohn Marinosearched, and quadratic worst-case time in the length of the used regular 9126af9a77bSJohn Marinoexpression. 9136af9a77bSJohn MarinoWhen back-references are used, a slower, backtracking engine is used. 9146af9a77bSJohn MarinoWhile all backtracking matching engines suffer from extreme slowness for certain 9156af9a77bSJohn Marinopathological cases, the normal engines doesn't suffer from these cases. 9166af9a77bSJohn MarinoIt is advised to avoid back-references whenever possible. 9176af9a77bSJohn Marino.Pp 9186af9a77bSJohn MarinoThe 9196af9a77bSJohn Marino.Fn regcomp 9206af9a77bSJohn Marinovariants 9216af9a77bSJohn Marinoimplements bounded repetitions by macro expansion, 9226af9a77bSJohn Marinowhich is costly in time and space if counts are large 9236af9a77bSJohn Marinoor bounded repetitions are nested. 9246af9a77bSJohn MarinoAn RE like, say, 9256af9a77bSJohn Marino.Ql "((((a{1,100}){1,100}){1,100}){1,100}){1,100}" 9266af9a77bSJohn Marinowill (eventually) run almost any existing machine out of swap space. 9276af9a77bSJohn Marino.Pp 9286af9a77bSJohn MarinoDue to a mistake in 9296af9a77bSJohn Marino.St -p1003.2 , 9306af9a77bSJohn Marinothings like 9316af9a77bSJohn Marino.Ql "a)b" 9326af9a77bSJohn Marinoare legal REs because 9336af9a77bSJohn Marino.Ql )\& 9346af9a77bSJohn Marinois 9356af9a77bSJohn Marinoa special character only in the presence of a previous unmatched 9366af9a77bSJohn Marino.Ql (\& . 9376af9a77bSJohn MarinoThis cannot be fixed until the spec is fixed. 9386af9a77bSJohn Marino.Pp 9396af9a77bSJohn MarinoThe standard's definition of back references is vague. 9406af9a77bSJohn MarinoFor example, does 9416af9a77bSJohn Marino.Ql "a\e(\e(b\e)*\e2\e)*d" 9426af9a77bSJohn Marinomatch 9436af9a77bSJohn Marino.Ql "abbbd" ? 9446af9a77bSJohn MarinoUntil the standard is clarified, 9456af9a77bSJohn Marinobehavior in such cases should not be relied on. 946