1*9880d681SAndroid Build Coastguard Worker.\" $OpenBSD: re_format.7,v 1.14 2007/05/31 19:19:30 jmc Exp $ 2*9880d681SAndroid Build Coastguard Worker.\" 3*9880d681SAndroid Build Coastguard Worker.\" Copyright (c) 1997, Phillip F Knaack. All rights reserved. 4*9880d681SAndroid Build Coastguard Worker.\" 5*9880d681SAndroid Build Coastguard Worker.\" Copyright (c) 1992, 1993, 1994 Henry Spencer. 6*9880d681SAndroid Build Coastguard Worker.\" Copyright (c) 1992, 1993, 1994 7*9880d681SAndroid Build Coastguard Worker.\" The Regents of the University of California. All rights reserved. 8*9880d681SAndroid Build Coastguard Worker.\" 9*9880d681SAndroid Build Coastguard Worker.\" This code is derived from software contributed to Berkeley by 10*9880d681SAndroid Build Coastguard Worker.\" Henry Spencer. 11*9880d681SAndroid Build Coastguard Worker.\" 12*9880d681SAndroid Build Coastguard Worker.\" Redistribution and use in source and binary forms, with or without 13*9880d681SAndroid Build Coastguard Worker.\" modification, are permitted provided that the following conditions 14*9880d681SAndroid Build Coastguard Worker.\" are met: 15*9880d681SAndroid Build Coastguard Worker.\" 1. Redistributions of source code must retain the above copyright 16*9880d681SAndroid Build Coastguard Worker.\" notice, this list of conditions and the following disclaimer. 17*9880d681SAndroid Build Coastguard Worker.\" 2. Redistributions in binary form must reproduce the above copyright 18*9880d681SAndroid Build Coastguard Worker.\" notice, this list of conditions and the following disclaimer in the 19*9880d681SAndroid Build Coastguard Worker.\" documentation and/or other materials provided with the distribution. 20*9880d681SAndroid Build Coastguard Worker.\" 3. Neither the name of the University nor the names of its contributors 21*9880d681SAndroid Build Coastguard Worker.\" may be used to endorse or promote products derived from this software 22*9880d681SAndroid Build Coastguard Worker.\" without specific prior written permission. 23*9880d681SAndroid Build Coastguard Worker.\" 24*9880d681SAndroid Build Coastguard Worker.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25*9880d681SAndroid Build Coastguard Worker.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26*9880d681SAndroid Build Coastguard Worker.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27*9880d681SAndroid Build Coastguard Worker.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28*9880d681SAndroid Build Coastguard Worker.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29*9880d681SAndroid Build Coastguard Worker.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30*9880d681SAndroid Build Coastguard Worker.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31*9880d681SAndroid Build Coastguard Worker.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32*9880d681SAndroid Build Coastguard Worker.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33*9880d681SAndroid Build Coastguard Worker.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34*9880d681SAndroid Build Coastguard Worker.\" SUCH DAMAGE. 35*9880d681SAndroid Build Coastguard Worker.\" 36*9880d681SAndroid Build Coastguard Worker.\" @(#)re_format.7 8.3 (Berkeley) 3/20/94 37*9880d681SAndroid Build Coastguard Worker.\" 38*9880d681SAndroid Build Coastguard Worker.Dd $Mdocdate: May 31 2007 $ 39*9880d681SAndroid Build Coastguard Worker.Dt RE_FORMAT 7 40*9880d681SAndroid Build Coastguard Worker.Os 41*9880d681SAndroid Build Coastguard Worker.Sh NAME 42*9880d681SAndroid Build Coastguard Worker.Nm re_format 43*9880d681SAndroid Build Coastguard Worker.Nd POSIX regular expressions 44*9880d681SAndroid Build Coastguard Worker.Sh DESCRIPTION 45*9880d681SAndroid Build Coastguard WorkerRegular expressions (REs), 46*9880d681SAndroid Build Coastguard Workeras defined in 47*9880d681SAndroid Build Coastguard Worker.St -p1003.1-2004 , 48*9880d681SAndroid Build Coastguard Workercome in two forms: 49*9880d681SAndroid Build Coastguard Workerbasic regular expressions 50*9880d681SAndroid Build Coastguard Worker(BREs) 51*9880d681SAndroid Build Coastguard Workerand extended regular expressions 52*9880d681SAndroid Build Coastguard Worker(EREs). 53*9880d681SAndroid Build Coastguard WorkerBoth forms of regular expressions are supported 54*9880d681SAndroid Build Coastguard Workerby the interfaces described in 55*9880d681SAndroid Build Coastguard Worker.Xr regex 3 . 56*9880d681SAndroid Build Coastguard WorkerApplications dealing with regular expressions 57*9880d681SAndroid Build Coastguard Workermay use one or the other form 58*9880d681SAndroid Build Coastguard Worker(or indeed both). 59*9880d681SAndroid Build Coastguard WorkerFor example, 60*9880d681SAndroid Build Coastguard Worker.Xr ed 1 61*9880d681SAndroid Build Coastguard Workeruses BREs, 62*9880d681SAndroid Build Coastguard Workerwhilst 63*9880d681SAndroid Build Coastguard Worker.Xr egrep 1 64*9880d681SAndroid Build Coastguard Workertalks EREs. 65*9880d681SAndroid Build Coastguard WorkerConsult the manual page for the specific application to find out which 66*9880d681SAndroid Build Coastguard Workerit uses. 67*9880d681SAndroid Build Coastguard Worker.Pp 68*9880d681SAndroid Build Coastguard WorkerPOSIX leaves some aspects of RE syntax and semantics open; 69*9880d681SAndroid Build Coastguard Worker.Sq ** 70*9880d681SAndroid Build Coastguard Workermarks decisions on these aspects that 71*9880d681SAndroid Build Coastguard Workermay not be fully portable to other POSIX implementations. 72*9880d681SAndroid Build Coastguard Worker.Pp 73*9880d681SAndroid Build Coastguard WorkerThis manual page first describes regular expressions in general, 74*9880d681SAndroid Build Coastguard Workerspecifically extended regular expressions, 75*9880d681SAndroid Build Coastguard Workerand then discusses differences between them and basic regular expressions. 76*9880d681SAndroid Build Coastguard Worker.Sh EXTENDED REGULAR EXPRESSIONS 77*9880d681SAndroid Build Coastguard WorkerAn ERE is one** or more non-empty** 78*9880d681SAndroid Build Coastguard Worker.Em branches , 79*9880d681SAndroid Build Coastguard Workerseparated by 80*9880d681SAndroid Build Coastguard Worker.Sq \*(Ba . 81*9880d681SAndroid Build Coastguard WorkerIt matches anything that matches one of the branches. 82*9880d681SAndroid Build Coastguard Worker.Pp 83*9880d681SAndroid Build Coastguard WorkerA branch is one** or more 84*9880d681SAndroid Build Coastguard Worker.Em pieces , 85*9880d681SAndroid Build Coastguard Workerconcatenated. 86*9880d681SAndroid Build Coastguard WorkerIt matches a match for the first, followed by a match for the second, etc. 87*9880d681SAndroid Build Coastguard Worker.Pp 88*9880d681SAndroid Build Coastguard WorkerA piece is an 89*9880d681SAndroid Build Coastguard Worker.Em atom 90*9880d681SAndroid Build Coastguard Workerpossibly followed by a single** 91*9880d681SAndroid Build Coastguard Worker.Sq * , 92*9880d681SAndroid Build Coastguard Worker.Sq + , 93*9880d681SAndroid Build Coastguard Worker.Sq ?\& , 94*9880d681SAndroid Build Coastguard Workeror 95*9880d681SAndroid Build Coastguard Worker.Em bound . 96*9880d681SAndroid Build Coastguard WorkerAn atom followed by 97*9880d681SAndroid Build Coastguard Worker.Sq * 98*9880d681SAndroid Build Coastguard Workermatches a sequence of 0 or more matches of the atom. 99*9880d681SAndroid Build Coastguard WorkerAn atom followed by 100*9880d681SAndroid Build Coastguard Worker.Sq + 101*9880d681SAndroid Build Coastguard Workermatches a sequence of 1 or more matches of the atom. 102*9880d681SAndroid Build Coastguard WorkerAn atom followed by 103*9880d681SAndroid Build Coastguard Worker.Sq ?\& 104*9880d681SAndroid Build Coastguard Workermatches a sequence of 0 or 1 matches of the atom. 105*9880d681SAndroid Build Coastguard Worker.Pp 106*9880d681SAndroid Build Coastguard WorkerA bound is 107*9880d681SAndroid Build Coastguard Worker.Sq { 108*9880d681SAndroid Build Coastguard Workerfollowed by an unsigned decimal integer, 109*9880d681SAndroid Build Coastguard Workerpossibly followed by 110*9880d681SAndroid Build Coastguard Worker.Sq ,\& 111*9880d681SAndroid Build Coastguard Workerpossibly followed by another unsigned decimal integer, 112*9880d681SAndroid Build Coastguard Workeralways followed by 113*9880d681SAndroid Build Coastguard Worker.Sq } . 114*9880d681SAndroid Build Coastguard WorkerThe integers must lie between 0 and 115*9880d681SAndroid Build Coastguard Worker.Dv RE_DUP_MAX 116*9880d681SAndroid Build Coastguard Worker(255**) inclusive, 117*9880d681SAndroid Build Coastguard Workerand if there are two of them, the first may not exceed the second. 118*9880d681SAndroid Build Coastguard WorkerAn atom followed by a bound containing one integer 119*9880d681SAndroid Build Coastguard Worker.Ar i 120*9880d681SAndroid Build Coastguard Workerand no comma matches 121*9880d681SAndroid Build Coastguard Workera sequence of exactly 122*9880d681SAndroid Build Coastguard Worker.Ar i 123*9880d681SAndroid Build Coastguard Workermatches of the atom. 124*9880d681SAndroid Build Coastguard WorkerAn atom followed by a bound 125*9880d681SAndroid Build Coastguard Workercontaining one integer 126*9880d681SAndroid Build Coastguard Worker.Ar i 127*9880d681SAndroid Build Coastguard Workerand a comma matches 128*9880d681SAndroid Build Coastguard Workera sequence of 129*9880d681SAndroid Build Coastguard Worker.Ar i 130*9880d681SAndroid Build Coastguard Workeror more matches of the atom. 131*9880d681SAndroid Build Coastguard WorkerAn atom followed by a bound 132*9880d681SAndroid Build Coastguard Workercontaining two integers 133*9880d681SAndroid Build Coastguard Worker.Ar i 134*9880d681SAndroid Build Coastguard Workerand 135*9880d681SAndroid Build Coastguard Worker.Ar j 136*9880d681SAndroid Build Coastguard Workermatches a sequence of 137*9880d681SAndroid Build Coastguard Worker.Ar i 138*9880d681SAndroid Build Coastguard Workerthrough 139*9880d681SAndroid Build Coastguard Worker.Ar j 140*9880d681SAndroid Build Coastguard Worker(inclusive) matches of the atom. 141*9880d681SAndroid Build Coastguard Worker.Pp 142*9880d681SAndroid Build Coastguard WorkerAn atom is a regular expression enclosed in 143*9880d681SAndroid Build Coastguard Worker.Sq () 144*9880d681SAndroid Build Coastguard Worker(matching a part of the regular expression), 145*9880d681SAndroid Build Coastguard Workeran empty set of 146*9880d681SAndroid Build Coastguard Worker.Sq () 147*9880d681SAndroid Build Coastguard Worker(matching the null string)**, 148*9880d681SAndroid Build Coastguard Workera 149*9880d681SAndroid Build Coastguard Worker.Em bracket expression 150*9880d681SAndroid Build Coastguard Worker(see below), 151*9880d681SAndroid Build Coastguard Worker.Sq .\& 152*9880d681SAndroid Build Coastguard Worker(matching any single character), 153*9880d681SAndroid Build Coastguard Worker.Sq ^ 154*9880d681SAndroid Build Coastguard Worker(matching the null string at the beginning of a line), 155*9880d681SAndroid Build Coastguard Worker.Sq $ 156*9880d681SAndroid Build Coastguard Worker(matching the null string at the end of a line), 157*9880d681SAndroid Build Coastguard Workera 158*9880d681SAndroid Build Coastguard Worker.Sq \e 159*9880d681SAndroid Build Coastguard Workerfollowed by one of the characters 160*9880d681SAndroid Build Coastguard Worker.Sq ^.[$()|*+?{\e 161*9880d681SAndroid Build Coastguard Worker(matching that character taken as an ordinary character), 162*9880d681SAndroid Build Coastguard Workera 163*9880d681SAndroid Build Coastguard Worker.Sq \e 164*9880d681SAndroid Build Coastguard Workerfollowed by any other character** 165*9880d681SAndroid Build Coastguard Worker(matching that character taken as an ordinary character, 166*9880d681SAndroid Build Coastguard Workeras if the 167*9880d681SAndroid Build Coastguard Worker.Sq \e 168*9880d681SAndroid Build Coastguard Workerhad not been present**), 169*9880d681SAndroid Build Coastguard Workeror a single character with no other significance (matching that character). 170*9880d681SAndroid Build Coastguard WorkerA 171*9880d681SAndroid Build Coastguard Worker.Sq { 172*9880d681SAndroid Build Coastguard Workerfollowed by a character other than a digit is an ordinary character, 173*9880d681SAndroid Build Coastguard Workernot the beginning of a bound**. 174*9880d681SAndroid Build Coastguard WorkerIt is illegal to end an RE with 175*9880d681SAndroid Build Coastguard Worker.Sq \e . 176*9880d681SAndroid Build Coastguard Worker.Pp 177*9880d681SAndroid Build Coastguard WorkerA bracket expression is a list of characters enclosed in 178*9880d681SAndroid Build Coastguard Worker.Sq [] . 179*9880d681SAndroid Build Coastguard WorkerIt normally matches any single character from the list (but see below). 180*9880d681SAndroid Build Coastguard WorkerIf the list begins with 181*9880d681SAndroid Build Coastguard Worker.Sq ^ , 182*9880d681SAndroid Build Coastguard Workerit matches any single character 183*9880d681SAndroid Build Coastguard Worker.Em not 184*9880d681SAndroid Build Coastguard Workerfrom the rest of the list 185*9880d681SAndroid Build Coastguard Worker(but see below). 186*9880d681SAndroid Build Coastguard WorkerIf two characters in the list are separated by 187*9880d681SAndroid Build Coastguard Worker.Sq - , 188*9880d681SAndroid Build Coastguard Workerthis is shorthand for the full 189*9880d681SAndroid Build Coastguard Worker.Em range 190*9880d681SAndroid Build Coastguard Workerof characters between those two (inclusive) in the 191*9880d681SAndroid Build Coastguard Workercollating sequence, e.g.\& 192*9880d681SAndroid Build Coastguard Worker.Sq [0-9] 193*9880d681SAndroid Build Coastguard Workerin ASCII matches any decimal digit. 194*9880d681SAndroid Build Coastguard WorkerIt is illegal** for two ranges to share an endpoint, e.g.\& 195*9880d681SAndroid Build Coastguard Worker.Sq a-c-e . 196*9880d681SAndroid Build Coastguard WorkerRanges are very collating-sequence-dependent, 197*9880d681SAndroid Build Coastguard Workerand portable programs should avoid relying on them. 198*9880d681SAndroid Build Coastguard Worker.Pp 199*9880d681SAndroid Build Coastguard WorkerTo include a literal 200*9880d681SAndroid Build Coastguard Worker.Sq ]\& 201*9880d681SAndroid Build Coastguard Workerin the list, make it the first character 202*9880d681SAndroid Build Coastguard Worker(following a possible 203*9880d681SAndroid Build Coastguard Worker.Sq ^ ) . 204*9880d681SAndroid Build Coastguard WorkerTo include a literal 205*9880d681SAndroid Build Coastguard Worker.Sq - , 206*9880d681SAndroid Build Coastguard Workermake it the first or last character, 207*9880d681SAndroid Build Coastguard Workeror the second endpoint of a range. 208*9880d681SAndroid Build Coastguard WorkerTo use a literal 209*9880d681SAndroid Build Coastguard Worker.Sq - 210*9880d681SAndroid Build Coastguard Workeras the first endpoint of a range, 211*9880d681SAndroid Build Coastguard Workerenclose it in 212*9880d681SAndroid Build Coastguard Worker.Sq [. 213*9880d681SAndroid Build Coastguard Workerand 214*9880d681SAndroid Build Coastguard Worker.Sq .] 215*9880d681SAndroid Build Coastguard Workerto make it a collating element (see below). 216*9880d681SAndroid Build Coastguard WorkerWith the exception of these and some combinations using 217*9880d681SAndroid Build Coastguard Worker.Sq [ 218*9880d681SAndroid Build Coastguard Worker(see next paragraphs), 219*9880d681SAndroid Build Coastguard Workerall other special characters, including 220*9880d681SAndroid Build Coastguard Worker.Sq \e , 221*9880d681SAndroid Build Coastguard Workerlose their special significance within a bracket expression. 222*9880d681SAndroid Build Coastguard Worker.Pp 223*9880d681SAndroid Build Coastguard WorkerWithin a bracket expression, a collating element 224*9880d681SAndroid Build Coastguard Worker(a character, 225*9880d681SAndroid Build Coastguard Workera multi-character sequence that collates as if it were a single character, 226*9880d681SAndroid Build Coastguard Workeror a collating-sequence name for either) 227*9880d681SAndroid Build Coastguard Workerenclosed in 228*9880d681SAndroid Build Coastguard Worker.Sq [. 229*9880d681SAndroid Build Coastguard Workerand 230*9880d681SAndroid Build Coastguard Worker.Sq .] 231*9880d681SAndroid Build Coastguard Workerstands for the sequence of characters of that collating element. 232*9880d681SAndroid Build Coastguard WorkerThe sequence is a single element of the bracket expression's list. 233*9880d681SAndroid Build Coastguard WorkerA bracket expression containing a multi-character collating element 234*9880d681SAndroid Build Coastguard Workercan thus match more than one character, 235*9880d681SAndroid Build Coastguard Workere.g. if the collating sequence includes a 236*9880d681SAndroid Build Coastguard Worker.Sq ch 237*9880d681SAndroid Build Coastguard Workercollating element, 238*9880d681SAndroid Build Coastguard Workerthen the RE 239*9880d681SAndroid Build Coastguard Worker.Sq [[.ch.]]*c 240*9880d681SAndroid Build Coastguard Workermatches the first five characters of 241*9880d681SAndroid Build Coastguard Worker.Sq chchcc . 242*9880d681SAndroid Build Coastguard Worker.Pp 243*9880d681SAndroid Build Coastguard WorkerWithin a bracket expression, a collating element enclosed in 244*9880d681SAndroid Build Coastguard Worker.Sq [= 245*9880d681SAndroid Build Coastguard Workerand 246*9880d681SAndroid Build Coastguard Worker.Sq =] 247*9880d681SAndroid Build Coastguard Workeris an equivalence class, standing for the sequences of characters 248*9880d681SAndroid Build Coastguard Workerof all collating elements equivalent to that one, including itself. 249*9880d681SAndroid Build Coastguard Worker(If there are no other equivalent collating elements, 250*9880d681SAndroid Build Coastguard Workerthe treatment is as if the enclosing delimiters were 251*9880d681SAndroid Build Coastguard Worker.Sq [. 252*9880d681SAndroid Build Coastguard Workerand 253*9880d681SAndroid Build Coastguard Worker.Sq .] . ) 254*9880d681SAndroid Build Coastguard WorkerFor example, if 255*9880d681SAndroid Build Coastguard Worker.Sq x 256*9880d681SAndroid Build Coastguard Workerand 257*9880d681SAndroid Build Coastguard Worker.Sq y 258*9880d681SAndroid Build Coastguard Workerare the members of an equivalence class, 259*9880d681SAndroid Build Coastguard Workerthen 260*9880d681SAndroid Build Coastguard Worker.Sq [[=x=]] , 261*9880d681SAndroid Build Coastguard Worker.Sq [[=y=]] , 262*9880d681SAndroid Build Coastguard Workerand 263*9880d681SAndroid Build Coastguard Worker.Sq [xy] 264*9880d681SAndroid Build Coastguard Workerare all synonymous. 265*9880d681SAndroid Build Coastguard WorkerAn equivalence class may not** be an endpoint of a range. 266*9880d681SAndroid Build Coastguard Worker.Pp 267*9880d681SAndroid Build Coastguard WorkerWithin a bracket expression, the name of a 268*9880d681SAndroid Build Coastguard Worker.Em character class 269*9880d681SAndroid Build Coastguard Workerenclosed 270*9880d681SAndroid Build Coastguard Workerin 271*9880d681SAndroid Build Coastguard Worker.Sq [: 272*9880d681SAndroid Build Coastguard Workerand 273*9880d681SAndroid Build Coastguard Worker.Sq :] 274*9880d681SAndroid Build Coastguard Workerstands for the list of all characters belonging to that class. 275*9880d681SAndroid Build Coastguard WorkerStandard character class names are: 276*9880d681SAndroid Build Coastguard Worker.Bd -literal -offset indent 277*9880d681SAndroid Build Coastguard Workeralnum digit punct 278*9880d681SAndroid Build Coastguard Workeralpha graph space 279*9880d681SAndroid Build Coastguard Workerblank lower upper 280*9880d681SAndroid Build Coastguard Workercntrl print xdigit 281*9880d681SAndroid Build Coastguard Worker.Ed 282*9880d681SAndroid Build Coastguard Worker.Pp 283*9880d681SAndroid Build Coastguard WorkerThese stand for the character classes defined in 284*9880d681SAndroid Build Coastguard Worker.Xr ctype 3 . 285*9880d681SAndroid Build Coastguard WorkerA locale may provide others. 286*9880d681SAndroid Build Coastguard WorkerA character class may not be used as an endpoint of a range. 287*9880d681SAndroid Build Coastguard Worker.Pp 288*9880d681SAndroid Build Coastguard WorkerThere are two special cases** of bracket expressions: 289*9880d681SAndroid Build Coastguard Workerthe bracket expressions 290*9880d681SAndroid Build Coastguard Worker.Sq [[:<:]] 291*9880d681SAndroid Build Coastguard Workerand 292*9880d681SAndroid Build Coastguard Worker.Sq [[:>:]] 293*9880d681SAndroid Build Coastguard Workermatch the null string at the beginning and end of a word, respectively. 294*9880d681SAndroid Build Coastguard WorkerA word is defined as a sequence of 295*9880d681SAndroid Build Coastguard Workercharacters starting and ending with a word character 296*9880d681SAndroid Build Coastguard Workerwhich is neither preceded nor followed by 297*9880d681SAndroid Build Coastguard Workerword characters. 298*9880d681SAndroid Build Coastguard WorkerA word character is an 299*9880d681SAndroid Build Coastguard Worker.Em alnum 300*9880d681SAndroid Build Coastguard Workercharacter (as defined by 301*9880d681SAndroid Build Coastguard Worker.Xr ctype 3 ) 302*9880d681SAndroid Build Coastguard Workeror an underscore. 303*9880d681SAndroid Build Coastguard WorkerThis is an extension, 304*9880d681SAndroid Build Coastguard Workercompatible with but not specified by POSIX, 305*9880d681SAndroid Build Coastguard Workerand should be used with 306*9880d681SAndroid Build Coastguard Workercaution in software intended to be portable to other systems. 307*9880d681SAndroid Build Coastguard Worker.Pp 308*9880d681SAndroid Build Coastguard WorkerIn the event that an RE could match more than one substring of a given 309*9880d681SAndroid Build Coastguard Workerstring, 310*9880d681SAndroid Build Coastguard Workerthe RE matches the one starting earliest in the string. 311*9880d681SAndroid Build Coastguard WorkerIf the RE could match more than one substring starting at that point, 312*9880d681SAndroid Build Coastguard Workerit matches the longest. 313*9880d681SAndroid Build Coastguard WorkerSubexpressions also match the longest possible substrings, subject to 314*9880d681SAndroid Build Coastguard Workerthe constraint that the whole match be as long as possible, 315*9880d681SAndroid Build Coastguard Workerwith subexpressions starting earlier in the RE taking priority over 316*9880d681SAndroid Build Coastguard Workerones starting later. 317*9880d681SAndroid Build Coastguard WorkerNote that higher-level subexpressions thus take priority over 318*9880d681SAndroid Build Coastguard Workertheir lower-level component subexpressions. 319*9880d681SAndroid Build Coastguard Worker.Pp 320*9880d681SAndroid Build Coastguard WorkerMatch lengths are measured in characters, not collating elements. 321*9880d681SAndroid Build Coastguard WorkerA null string is considered longer than no match at all. 322*9880d681SAndroid Build Coastguard WorkerFor example, 323*9880d681SAndroid Build Coastguard Worker.Sq bb* 324*9880d681SAndroid Build Coastguard Workermatches the three middle characters of 325*9880d681SAndroid Build Coastguard Worker.Sq abbbc ; 326*9880d681SAndroid Build Coastguard Worker.Sq (wee|week)(knights|nights) 327*9880d681SAndroid Build Coastguard Workermatches all ten characters of 328*9880d681SAndroid Build Coastguard Worker.Sq weeknights ; 329*9880d681SAndroid Build Coastguard Workerwhen 330*9880d681SAndroid Build Coastguard Worker.Sq (.*).* 331*9880d681SAndroid Build Coastguard Workeris matched against 332*9880d681SAndroid Build Coastguard Worker.Sq abc , 333*9880d681SAndroid Build Coastguard Workerthe parenthesized subexpression matches all three characters; 334*9880d681SAndroid Build Coastguard Workerand when 335*9880d681SAndroid Build Coastguard Worker.Sq (a*)* 336*9880d681SAndroid Build Coastguard Workeris matched against 337*9880d681SAndroid Build Coastguard Worker.Sq bc , 338*9880d681SAndroid Build Coastguard Workerboth the whole RE and the parenthesized subexpression match the null string. 339*9880d681SAndroid Build Coastguard Worker.Pp 340*9880d681SAndroid Build Coastguard WorkerIf case-independent matching is specified, 341*9880d681SAndroid Build Coastguard Workerthe effect is much as if all case distinctions had vanished from the 342*9880d681SAndroid Build Coastguard Workeralphabet. 343*9880d681SAndroid Build Coastguard WorkerWhen an alphabetic that exists in multiple cases appears as an 344*9880d681SAndroid Build Coastguard Workerordinary character outside a bracket expression, it is effectively 345*9880d681SAndroid Build Coastguard Workertransformed into a bracket expression containing both cases, 346*9880d681SAndroid Build Coastguard Workere.g.\& 347*9880d681SAndroid Build Coastguard Worker.Sq x 348*9880d681SAndroid Build Coastguard Workerbecomes 349*9880d681SAndroid Build Coastguard Worker.Sq [xX] . 350*9880d681SAndroid Build Coastguard WorkerWhen it appears inside a bracket expression, 351*9880d681SAndroid Build Coastguard Workerall case counterparts of it are added to the bracket expression, 352*9880d681SAndroid Build Coastguard Workerso that, for example, 353*9880d681SAndroid Build Coastguard Worker.Sq [x] 354*9880d681SAndroid Build Coastguard Workerbecomes 355*9880d681SAndroid Build Coastguard Worker.Sq [xX] 356*9880d681SAndroid Build Coastguard Workerand 357*9880d681SAndroid Build Coastguard Worker.Sq [^x] 358*9880d681SAndroid Build Coastguard Workerbecomes 359*9880d681SAndroid Build Coastguard Worker.Sq [^xX] . 360*9880d681SAndroid Build Coastguard Worker.Pp 361*9880d681SAndroid Build Coastguard WorkerNo particular limit is imposed on the length of REs**. 362*9880d681SAndroid Build Coastguard WorkerPrograms intended to be portable should not employ REs longer 363*9880d681SAndroid Build Coastguard Workerthan 256 bytes, 364*9880d681SAndroid Build Coastguard Workeras an implementation can refuse to accept such REs and remain 365*9880d681SAndroid Build Coastguard WorkerPOSIX-compliant. 366*9880d681SAndroid Build Coastguard Worker.Pp 367*9880d681SAndroid Build Coastguard WorkerThe following is a list of extended regular expressions: 368*9880d681SAndroid Build Coastguard Worker.Bl -tag -width Ds 369*9880d681SAndroid Build Coastguard Worker.It Ar c 370*9880d681SAndroid Build Coastguard WorkerAny character 371*9880d681SAndroid Build Coastguard Worker.Ar c 372*9880d681SAndroid Build Coastguard Workernot listed below matches itself. 373*9880d681SAndroid Build Coastguard Worker.It \e Ns Ar c 374*9880d681SAndroid Build Coastguard WorkerAny backslash-escaped character 375*9880d681SAndroid Build Coastguard Worker.Ar c 376*9880d681SAndroid Build Coastguard Workermatches itself. 377*9880d681SAndroid Build Coastguard Worker.It \&. 378*9880d681SAndroid Build Coastguard WorkerMatches any single character that is not a newline 379*9880d681SAndroid Build Coastguard Worker.Pq Sq \en . 380*9880d681SAndroid Build Coastguard Worker.It Bq Ar char-class 381*9880d681SAndroid Build Coastguard WorkerMatches any single character in 382*9880d681SAndroid Build Coastguard Worker.Ar char-class . 383*9880d681SAndroid Build Coastguard WorkerTo include a 384*9880d681SAndroid Build Coastguard Worker.Ql \&] 385*9880d681SAndroid Build Coastguard Workerin 386*9880d681SAndroid Build Coastguard Worker.Ar char-class , 387*9880d681SAndroid Build Coastguard Workerit must be the first character. 388*9880d681SAndroid Build Coastguard WorkerA range of characters may be specified by separating the end characters 389*9880d681SAndroid Build Coastguard Workerof the range with a 390*9880d681SAndroid Build Coastguard Worker.Ql - ; 391*9880d681SAndroid Build Coastguard Workere.g.\& 392*9880d681SAndroid Build Coastguard Worker.Ar a-z 393*9880d681SAndroid Build Coastguard Workerspecifies the lower case characters. 394*9880d681SAndroid Build Coastguard WorkerThe following literal expressions can also be used in 395*9880d681SAndroid Build Coastguard Worker.Ar char-class 396*9880d681SAndroid Build Coastguard Workerto specify sets of characters: 397*9880d681SAndroid Build Coastguard Worker.Bd -unfilled -offset indent 398*9880d681SAndroid Build Coastguard Worker[:alnum:] [:cntrl:] [:lower:] [:space:] 399*9880d681SAndroid Build Coastguard Worker[:alpha:] [:digit:] [:print:] [:upper:] 400*9880d681SAndroid Build Coastguard Worker[:blank:] [:graph:] [:punct:] [:xdigit:] 401*9880d681SAndroid Build Coastguard Worker.Ed 402*9880d681SAndroid Build Coastguard Worker.Pp 403*9880d681SAndroid Build Coastguard WorkerIf 404*9880d681SAndroid Build Coastguard Worker.Ql - 405*9880d681SAndroid Build Coastguard Workerappears as the first or last character of 406*9880d681SAndroid Build Coastguard Worker.Ar char-class , 407*9880d681SAndroid Build Coastguard Workerthen it matches itself. 408*9880d681SAndroid Build Coastguard WorkerAll other characters in 409*9880d681SAndroid Build Coastguard Worker.Ar char-class 410*9880d681SAndroid Build Coastguard Workermatch themselves. 411*9880d681SAndroid Build Coastguard Worker.Pp 412*9880d681SAndroid Build Coastguard WorkerPatterns in 413*9880d681SAndroid Build Coastguard Worker.Ar char-class 414*9880d681SAndroid Build Coastguard Workerof the form 415*9880d681SAndroid Build Coastguard Worker.Eo [. 416*9880d681SAndroid Build Coastguard Worker.Ar col-elm 417*9880d681SAndroid Build Coastguard Worker.Ec .]\& 418*9880d681SAndroid Build Coastguard Workeror 419*9880d681SAndroid Build Coastguard Worker.Eo [= 420*9880d681SAndroid Build Coastguard Worker.Ar col-elm 421*9880d681SAndroid Build Coastguard Worker.Ec =]\& , 422*9880d681SAndroid Build Coastguard Workerwhere 423*9880d681SAndroid Build Coastguard Worker.Ar col-elm 424*9880d681SAndroid Build Coastguard Workeris a collating element, are interpreted according to 425*9880d681SAndroid Build Coastguard Worker.Xr setlocale 3 426*9880d681SAndroid Build Coastguard Worker.Pq not currently supported . 427*9880d681SAndroid Build Coastguard Worker.It Bq ^ Ns Ar char-class 428*9880d681SAndroid Build Coastguard WorkerMatches any single character, other than newline, not in 429*9880d681SAndroid Build Coastguard Worker.Ar char-class . 430*9880d681SAndroid Build Coastguard Worker.Ar char-class 431*9880d681SAndroid Build Coastguard Workeris defined as above. 432*9880d681SAndroid Build Coastguard Worker.It ^ 433*9880d681SAndroid Build Coastguard WorkerIf 434*9880d681SAndroid Build Coastguard Worker.Sq ^ 435*9880d681SAndroid Build Coastguard Workeris the first character of a regular expression, then it 436*9880d681SAndroid Build Coastguard Workeranchors the regular expression to the beginning of a line. 437*9880d681SAndroid Build Coastguard WorkerOtherwise, it matches itself. 438*9880d681SAndroid Build Coastguard Worker.It $ 439*9880d681SAndroid Build Coastguard WorkerIf 440*9880d681SAndroid Build Coastguard Worker.Sq $ 441*9880d681SAndroid Build Coastguard Workeris the last character of a regular expression, 442*9880d681SAndroid Build Coastguard Workerit anchors the regular expression to the end of a line. 443*9880d681SAndroid Build Coastguard WorkerOtherwise, it matches itself. 444*9880d681SAndroid Build Coastguard Worker.It [[:<:]] 445*9880d681SAndroid Build Coastguard WorkerAnchors the single character regular expression or subexpression 446*9880d681SAndroid Build Coastguard Workerimmediately following it to the beginning of a word. 447*9880d681SAndroid Build Coastguard Worker.It [[:>:]] 448*9880d681SAndroid Build Coastguard WorkerAnchors the single character regular expression or subexpression 449*9880d681SAndroid Build Coastguard Workerimmediately following it to the end of a word. 450*9880d681SAndroid Build Coastguard Worker.It Pq Ar re 451*9880d681SAndroid Build Coastguard WorkerDefines a subexpression 452*9880d681SAndroid Build Coastguard Worker.Ar re . 453*9880d681SAndroid Build Coastguard WorkerAny set of characters enclosed in parentheses 454*9880d681SAndroid Build Coastguard Workermatches whatever the set of characters without parentheses matches 455*9880d681SAndroid Build Coastguard Worker(that is a long-winded way of saying the constructs 456*9880d681SAndroid Build Coastguard Worker.Sq (re) 457*9880d681SAndroid Build Coastguard Workerand 458*9880d681SAndroid Build Coastguard Worker.Sq re 459*9880d681SAndroid Build Coastguard Workermatch identically). 460*9880d681SAndroid Build Coastguard Worker.It * 461*9880d681SAndroid Build Coastguard WorkerMatches the single character regular expression or subexpression 462*9880d681SAndroid Build Coastguard Workerimmediately preceding it zero or more times. 463*9880d681SAndroid Build Coastguard WorkerIf 464*9880d681SAndroid Build Coastguard Worker.Sq * 465*9880d681SAndroid Build Coastguard Workeris the first character of a regular expression or subexpression, 466*9880d681SAndroid Build Coastguard Workerthen it matches itself. 467*9880d681SAndroid Build Coastguard WorkerThe 468*9880d681SAndroid Build Coastguard Worker.Sq * 469*9880d681SAndroid Build Coastguard Workeroperator sometimes yields unexpected results. 470*9880d681SAndroid Build Coastguard WorkerFor example, the regular expression 471*9880d681SAndroid Build Coastguard Worker.Ar b* 472*9880d681SAndroid Build Coastguard Workermatches the beginning of the string 473*9880d681SAndroid Build Coastguard Worker.Qq abbb 474*9880d681SAndroid Build Coastguard Worker(as opposed to the substring 475*9880d681SAndroid Build Coastguard Worker.Qq bbb ) , 476*9880d681SAndroid Build Coastguard Workersince a null match is the only leftmost match. 477*9880d681SAndroid Build Coastguard Worker.It + 478*9880d681SAndroid Build Coastguard WorkerMatches the singular character regular expression 479*9880d681SAndroid Build Coastguard Workeror subexpression immediately preceding it 480*9880d681SAndroid Build Coastguard Workerone or more times. 481*9880d681SAndroid Build Coastguard Worker.It ? 482*9880d681SAndroid Build Coastguard WorkerMatches the singular character regular expression 483*9880d681SAndroid Build Coastguard Workeror subexpression immediately preceding it 484*9880d681SAndroid Build Coastguard Worker0 or 1 times. 485*9880d681SAndroid Build Coastguard Worker.Sm off 486*9880d681SAndroid Build Coastguard Worker.It Xo 487*9880d681SAndroid Build Coastguard Worker.Pf { Ar n , m No }\ \& 488*9880d681SAndroid Build Coastguard Worker.Pf { Ar n , No }\ \& 489*9880d681SAndroid Build Coastguard Worker.Pf { Ar n No } 490*9880d681SAndroid Build Coastguard Worker.Xc 491*9880d681SAndroid Build Coastguard Worker.Sm on 492*9880d681SAndroid Build Coastguard WorkerMatches the single character regular expression or subexpression 493*9880d681SAndroid Build Coastguard Workerimmediately preceding it at least 494*9880d681SAndroid Build Coastguard Worker.Ar n 495*9880d681SAndroid Build Coastguard Workerand at most 496*9880d681SAndroid Build Coastguard Worker.Ar m 497*9880d681SAndroid Build Coastguard Workertimes. 498*9880d681SAndroid Build Coastguard WorkerIf 499*9880d681SAndroid Build Coastguard Worker.Ar m 500*9880d681SAndroid Build Coastguard Workeris omitted, then it matches at least 501*9880d681SAndroid Build Coastguard Worker.Ar n 502*9880d681SAndroid Build Coastguard Workertimes. 503*9880d681SAndroid Build Coastguard WorkerIf the comma is also omitted, then it matches exactly 504*9880d681SAndroid Build Coastguard Worker.Ar n 505*9880d681SAndroid Build Coastguard Workertimes. 506*9880d681SAndroid Build Coastguard Worker.It \*(Ba 507*9880d681SAndroid Build Coastguard WorkerUsed to separate patterns. 508*9880d681SAndroid Build Coastguard WorkerFor example, 509*9880d681SAndroid Build Coastguard Workerthe pattern 510*9880d681SAndroid Build Coastguard Worker.Sq cat\*(Badog 511*9880d681SAndroid Build Coastguard Workermatches either 512*9880d681SAndroid Build Coastguard Worker.Sq cat 513*9880d681SAndroid Build Coastguard Workeror 514*9880d681SAndroid Build Coastguard Worker.Sq dog . 515*9880d681SAndroid Build Coastguard Worker.El 516*9880d681SAndroid Build Coastguard Worker.Sh BASIC REGULAR EXPRESSIONS 517*9880d681SAndroid Build Coastguard WorkerBasic regular expressions differ in several respects: 518*9880d681SAndroid Build Coastguard Worker.Bl -bullet -offset 3n 519*9880d681SAndroid Build Coastguard Worker.It 520*9880d681SAndroid Build Coastguard Worker.Sq \*(Ba , 521*9880d681SAndroid Build Coastguard Worker.Sq + , 522*9880d681SAndroid Build Coastguard Workerand 523*9880d681SAndroid Build Coastguard Worker.Sq ?\& 524*9880d681SAndroid Build Coastguard Workerare ordinary characters and there is no equivalent 525*9880d681SAndroid Build Coastguard Workerfor their functionality. 526*9880d681SAndroid Build Coastguard Worker.It 527*9880d681SAndroid Build Coastguard WorkerThe delimiters for bounds are 528*9880d681SAndroid Build Coastguard Worker.Sq \e{ 529*9880d681SAndroid Build Coastguard Workerand 530*9880d681SAndroid Build Coastguard Worker.Sq \e} , 531*9880d681SAndroid Build Coastguard Workerwith 532*9880d681SAndroid Build Coastguard Worker.Sq { 533*9880d681SAndroid Build Coastguard Workerand 534*9880d681SAndroid Build Coastguard Worker.Sq } 535*9880d681SAndroid Build Coastguard Workerby themselves ordinary characters. 536*9880d681SAndroid Build Coastguard Worker.It 537*9880d681SAndroid Build Coastguard WorkerThe parentheses for nested subexpressions are 538*9880d681SAndroid Build Coastguard Worker.Sq \e( 539*9880d681SAndroid Build Coastguard Workerand 540*9880d681SAndroid Build Coastguard Worker.Sq \e) , 541*9880d681SAndroid Build Coastguard Workerwith 542*9880d681SAndroid Build Coastguard Worker.Sq ( 543*9880d681SAndroid Build Coastguard Workerand 544*9880d681SAndroid Build Coastguard Worker.Sq )\& 545*9880d681SAndroid Build Coastguard Workerby themselves ordinary characters. 546*9880d681SAndroid Build Coastguard Worker.It 547*9880d681SAndroid Build Coastguard Worker.Sq ^ 548*9880d681SAndroid Build Coastguard Workeris an ordinary character except at the beginning of the 549*9880d681SAndroid Build Coastguard WorkerRE or** the beginning of a parenthesized subexpression. 550*9880d681SAndroid Build Coastguard Worker.It 551*9880d681SAndroid Build Coastguard Worker.Sq $ 552*9880d681SAndroid Build Coastguard Workeris an ordinary character except at the end of the 553*9880d681SAndroid Build Coastguard WorkerRE or** the end of a parenthesized subexpression. 554*9880d681SAndroid Build Coastguard Worker.It 555*9880d681SAndroid Build Coastguard Worker.Sq * 556*9880d681SAndroid Build Coastguard Workeris an ordinary character if it appears at the beginning of the 557*9880d681SAndroid Build Coastguard WorkerRE or the beginning of a parenthesized subexpression 558*9880d681SAndroid Build Coastguard Worker(after a possible leading 559*9880d681SAndroid Build Coastguard Worker.Sq ^ ) . 560*9880d681SAndroid Build Coastguard Worker.It 561*9880d681SAndroid Build Coastguard WorkerFinally, there is one new type of atom, a 562*9880d681SAndroid Build Coastguard Worker.Em back-reference : 563*9880d681SAndroid Build Coastguard Worker.Sq \e 564*9880d681SAndroid Build Coastguard Workerfollowed by a non-zero decimal digit 565*9880d681SAndroid Build Coastguard Worker.Ar d 566*9880d681SAndroid Build Coastguard Workermatches the same sequence of characters matched by the 567*9880d681SAndroid Build Coastguard Worker.Ar d Ns th 568*9880d681SAndroid Build Coastguard Workerparenthesized subexpression 569*9880d681SAndroid Build Coastguard Worker(numbering subexpressions by the positions of their opening parentheses, 570*9880d681SAndroid Build Coastguard Workerleft to right), 571*9880d681SAndroid Build Coastguard Workerso that, for example, 572*9880d681SAndroid Build Coastguard Worker.Sq \e([bc]\e)\e1 573*9880d681SAndroid Build Coastguard Workermatches 574*9880d681SAndroid Build Coastguard Worker.Sq bb\& 575*9880d681SAndroid Build Coastguard Workeror 576*9880d681SAndroid Build Coastguard Worker.Sq cc 577*9880d681SAndroid Build Coastguard Workerbut not 578*9880d681SAndroid Build Coastguard Worker.Sq bc . 579*9880d681SAndroid Build Coastguard Worker.El 580*9880d681SAndroid Build Coastguard Worker.Pp 581*9880d681SAndroid Build Coastguard WorkerThe following is a list of basic regular expressions: 582*9880d681SAndroid Build Coastguard Worker.Bl -tag -width Ds 583*9880d681SAndroid Build Coastguard Worker.It Ar c 584*9880d681SAndroid Build Coastguard WorkerAny character 585*9880d681SAndroid Build Coastguard Worker.Ar c 586*9880d681SAndroid Build Coastguard Workernot listed below matches itself. 587*9880d681SAndroid Build Coastguard Worker.It \e Ns Ar c 588*9880d681SAndroid Build Coastguard WorkerAny backslash-escaped character 589*9880d681SAndroid Build Coastguard Worker.Ar c , 590*9880d681SAndroid Build Coastguard Workerexcept for 591*9880d681SAndroid Build Coastguard Worker.Sq { , 592*9880d681SAndroid Build Coastguard Worker.Sq } , 593*9880d681SAndroid Build Coastguard Worker.Sq \&( , 594*9880d681SAndroid Build Coastguard Workerand 595*9880d681SAndroid Build Coastguard Worker.Sq \&) , 596*9880d681SAndroid Build Coastguard Workermatches itself. 597*9880d681SAndroid Build Coastguard Worker.It \&. 598*9880d681SAndroid Build Coastguard WorkerMatches any single character that is not a newline 599*9880d681SAndroid Build Coastguard Worker.Pq Sq \en . 600*9880d681SAndroid Build Coastguard Worker.It Bq Ar char-class 601*9880d681SAndroid Build Coastguard WorkerMatches any single character in 602*9880d681SAndroid Build Coastguard Worker.Ar char-class . 603*9880d681SAndroid Build Coastguard WorkerTo include a 604*9880d681SAndroid Build Coastguard Worker.Ql \&] 605*9880d681SAndroid Build Coastguard Workerin 606*9880d681SAndroid Build Coastguard Worker.Ar char-class , 607*9880d681SAndroid Build Coastguard Workerit must be the first character. 608*9880d681SAndroid Build Coastguard WorkerA range of characters may be specified by separating the end characters 609*9880d681SAndroid Build Coastguard Workerof the range with a 610*9880d681SAndroid Build Coastguard Worker.Ql - ; 611*9880d681SAndroid Build Coastguard Workere.g.\& 612*9880d681SAndroid Build Coastguard Worker.Ar a-z 613*9880d681SAndroid Build Coastguard Workerspecifies the lower case characters. 614*9880d681SAndroid Build Coastguard WorkerThe following literal expressions can also be used in 615*9880d681SAndroid Build Coastguard Worker.Ar char-class 616*9880d681SAndroid Build Coastguard Workerto specify sets of characters: 617*9880d681SAndroid Build Coastguard Worker.Bd -unfilled -offset indent 618*9880d681SAndroid Build Coastguard Worker[:alnum:] [:cntrl:] [:lower:] [:space:] 619*9880d681SAndroid Build Coastguard Worker[:alpha:] [:digit:] [:print:] [:upper:] 620*9880d681SAndroid Build Coastguard Worker[:blank:] [:graph:] [:punct:] [:xdigit:] 621*9880d681SAndroid Build Coastguard Worker.Ed 622*9880d681SAndroid Build Coastguard Worker.Pp 623*9880d681SAndroid Build Coastguard WorkerIf 624*9880d681SAndroid Build Coastguard Worker.Ql - 625*9880d681SAndroid Build Coastguard Workerappears as the first or last character of 626*9880d681SAndroid Build Coastguard Worker.Ar char-class , 627*9880d681SAndroid Build Coastguard Workerthen it matches itself. 628*9880d681SAndroid Build Coastguard WorkerAll other characters in 629*9880d681SAndroid Build Coastguard Worker.Ar char-class 630*9880d681SAndroid Build Coastguard Workermatch themselves. 631*9880d681SAndroid Build Coastguard Worker.Pp 632*9880d681SAndroid Build Coastguard WorkerPatterns in 633*9880d681SAndroid Build Coastguard Worker.Ar char-class 634*9880d681SAndroid Build Coastguard Workerof the form 635*9880d681SAndroid Build Coastguard Worker.Eo [. 636*9880d681SAndroid Build Coastguard Worker.Ar col-elm 637*9880d681SAndroid Build Coastguard Worker.Ec .]\& 638*9880d681SAndroid Build Coastguard Workeror 639*9880d681SAndroid Build Coastguard Worker.Eo [= 640*9880d681SAndroid Build Coastguard Worker.Ar col-elm 641*9880d681SAndroid Build Coastguard Worker.Ec =]\& , 642*9880d681SAndroid Build Coastguard Workerwhere 643*9880d681SAndroid Build Coastguard Worker.Ar col-elm 644*9880d681SAndroid Build Coastguard Workeris a collating element, are interpreted according to 645*9880d681SAndroid Build Coastguard Worker.Xr setlocale 3 646*9880d681SAndroid Build Coastguard Worker.Pq not currently supported . 647*9880d681SAndroid Build Coastguard Worker.It Bq ^ Ns Ar char-class 648*9880d681SAndroid Build Coastguard WorkerMatches any single character, other than newline, not in 649*9880d681SAndroid Build Coastguard Worker.Ar char-class . 650*9880d681SAndroid Build Coastguard Worker.Ar char-class 651*9880d681SAndroid Build Coastguard Workeris defined as above. 652*9880d681SAndroid Build Coastguard Worker.It ^ 653*9880d681SAndroid Build Coastguard WorkerIf 654*9880d681SAndroid Build Coastguard Worker.Sq ^ 655*9880d681SAndroid Build Coastguard Workeris the first character of a regular expression, then it 656*9880d681SAndroid Build Coastguard Workeranchors the regular expression to the beginning of a line. 657*9880d681SAndroid Build Coastguard WorkerOtherwise, it matches itself. 658*9880d681SAndroid Build Coastguard Worker.It $ 659*9880d681SAndroid Build Coastguard WorkerIf 660*9880d681SAndroid Build Coastguard Worker.Sq $ 661*9880d681SAndroid Build Coastguard Workeris the last character of a regular expression, 662*9880d681SAndroid Build Coastguard Workerit anchors the regular expression to the end of a line. 663*9880d681SAndroid Build Coastguard WorkerOtherwise, it matches itself. 664*9880d681SAndroid Build Coastguard Worker.It [[:<:]] 665*9880d681SAndroid Build Coastguard WorkerAnchors the single character regular expression or subexpression 666*9880d681SAndroid Build Coastguard Workerimmediately following it to the beginning of a word. 667*9880d681SAndroid Build Coastguard Worker.It [[:>:]] 668*9880d681SAndroid Build Coastguard WorkerAnchors the single character regular expression or subexpression 669*9880d681SAndroid Build Coastguard Workerimmediately following it to the end of a word. 670*9880d681SAndroid Build Coastguard Worker.It \e( Ns Ar re Ns \e) 671*9880d681SAndroid Build Coastguard WorkerDefines a subexpression 672*9880d681SAndroid Build Coastguard Worker.Ar re . 673*9880d681SAndroid Build Coastguard WorkerSubexpressions may be nested. 674*9880d681SAndroid Build Coastguard WorkerA subsequent backreference of the form 675*9880d681SAndroid Build Coastguard Worker.Pf \e Ns Ar n , 676*9880d681SAndroid Build Coastguard Workerwhere 677*9880d681SAndroid Build Coastguard Worker.Ar n 678*9880d681SAndroid Build Coastguard Workeris a number in the range [1,9], expands to the text matched by the 679*9880d681SAndroid Build Coastguard Worker.Ar n Ns th 680*9880d681SAndroid Build Coastguard Workersubexpression. 681*9880d681SAndroid Build Coastguard WorkerFor example, the regular expression 682*9880d681SAndroid Build Coastguard Worker.Ar \e(.*\e)\e1 683*9880d681SAndroid Build Coastguard Workermatches any string consisting of identical adjacent substrings. 684*9880d681SAndroid Build Coastguard WorkerSubexpressions are ordered relative to their left delimiter. 685*9880d681SAndroid Build Coastguard Worker.It * 686*9880d681SAndroid Build Coastguard WorkerMatches the single character regular expression or subexpression 687*9880d681SAndroid Build Coastguard Workerimmediately preceding it zero or more times. 688*9880d681SAndroid Build Coastguard WorkerIf 689*9880d681SAndroid Build Coastguard Worker.Sq * 690*9880d681SAndroid Build Coastguard Workeris the first character of a regular expression or subexpression, 691*9880d681SAndroid Build Coastguard Workerthen it matches itself. 692*9880d681SAndroid Build Coastguard WorkerThe 693*9880d681SAndroid Build Coastguard Worker.Sq * 694*9880d681SAndroid Build Coastguard Workeroperator sometimes yields unexpected results. 695*9880d681SAndroid Build Coastguard WorkerFor example, the regular expression 696*9880d681SAndroid Build Coastguard Worker.Ar b* 697*9880d681SAndroid Build Coastguard Workermatches the beginning of the string 698*9880d681SAndroid Build Coastguard Worker.Qq abbb 699*9880d681SAndroid Build Coastguard Worker(as opposed to the substring 700*9880d681SAndroid Build Coastguard Worker.Qq bbb ) , 701*9880d681SAndroid Build Coastguard Workersince a null match is the only leftmost match. 702*9880d681SAndroid Build Coastguard Worker.Sm off 703*9880d681SAndroid Build Coastguard Worker.It Xo 704*9880d681SAndroid Build Coastguard Worker.Pf \e{ Ar n , m No \e}\ \& 705*9880d681SAndroid Build Coastguard Worker.Pf \e{ Ar n , No \e}\ \& 706*9880d681SAndroid Build Coastguard Worker.Pf \e{ Ar n No \e} 707*9880d681SAndroid Build Coastguard Worker.Xc 708*9880d681SAndroid Build Coastguard Worker.Sm on 709*9880d681SAndroid Build Coastguard WorkerMatches the single character regular expression or subexpression 710*9880d681SAndroid Build Coastguard Workerimmediately preceding it at least 711*9880d681SAndroid Build Coastguard Worker.Ar n 712*9880d681SAndroid Build Coastguard Workerand at most 713*9880d681SAndroid Build Coastguard Worker.Ar m 714*9880d681SAndroid Build Coastguard Workertimes. 715*9880d681SAndroid Build Coastguard WorkerIf 716*9880d681SAndroid Build Coastguard Worker.Ar m 717*9880d681SAndroid Build Coastguard Workeris omitted, then it matches at least 718*9880d681SAndroid Build Coastguard Worker.Ar n 719*9880d681SAndroid Build Coastguard Workertimes. 720*9880d681SAndroid Build Coastguard WorkerIf the comma is also omitted, then it matches exactly 721*9880d681SAndroid Build Coastguard Worker.Ar n 722*9880d681SAndroid Build Coastguard Workertimes. 723*9880d681SAndroid Build Coastguard Worker.El 724*9880d681SAndroid Build Coastguard Worker.Sh SEE ALSO 725*9880d681SAndroid Build Coastguard Worker.Xr ctype 3 , 726*9880d681SAndroid Build Coastguard Worker.Xr regex 3 727*9880d681SAndroid Build Coastguard Worker.Sh STANDARDS 728*9880d681SAndroid Build Coastguard Worker.St -p1003.1-2004 : 729*9880d681SAndroid Build Coastguard WorkerBase Definitions, Chapter 9 (Regular Expressions). 730*9880d681SAndroid Build Coastguard Worker.Sh BUGS 731*9880d681SAndroid Build Coastguard WorkerHaving two kinds of REs is a botch. 732*9880d681SAndroid Build Coastguard Worker.Pp 733*9880d681SAndroid Build Coastguard WorkerThe current POSIX spec says that 734*9880d681SAndroid Build Coastguard Worker.Sq )\& 735*9880d681SAndroid Build Coastguard Workeris an ordinary character in the absence of an unmatched 736*9880d681SAndroid Build Coastguard Worker.Sq ( ; 737*9880d681SAndroid Build Coastguard Workerthis was an unintentional result of a wording error, 738*9880d681SAndroid Build Coastguard Workerand change is likely. 739*9880d681SAndroid Build Coastguard WorkerAvoid relying on it. 740*9880d681SAndroid Build Coastguard Worker.Pp 741*9880d681SAndroid Build Coastguard WorkerBack-references are a dreadful botch, 742*9880d681SAndroid Build Coastguard Workerposing major problems for efficient implementations. 743*9880d681SAndroid Build Coastguard WorkerThey are also somewhat vaguely defined 744*9880d681SAndroid Build Coastguard Worker(does 745*9880d681SAndroid Build Coastguard Worker.Sq a\e(\e(b\e)*\e2\e)*d 746*9880d681SAndroid Build Coastguard Workermatch 747*9880d681SAndroid Build Coastguard Worker.Sq abbbd ? ) . 748*9880d681SAndroid Build Coastguard WorkerAvoid using them. 749*9880d681SAndroid Build Coastguard Worker.Pp 750*9880d681SAndroid Build Coastguard WorkerPOSIX's specification of case-independent matching is vague. 751*9880d681SAndroid Build Coastguard WorkerThe 752*9880d681SAndroid Build Coastguard Worker.Dq one case implies all cases 753*9880d681SAndroid Build Coastguard Workerdefinition given above 754*9880d681SAndroid Build Coastguard Workeris the current consensus among implementors as to the right interpretation. 755*9880d681SAndroid Build Coastguard Worker.Pp 756*9880d681SAndroid Build Coastguard WorkerThe syntax for word boundaries is incredibly ugly. 757