{
    "mode": "info",
    "parameter": "re_format",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/re_format/json",
    "generated": "2026-07-05T00:30:53Z",
    "sections": {
        "NAME": {
            "content": "regex - POSIX.2 regular expressions\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Regular  expressions (\"RE\"s), as defined in POSIX.2, come in two forms:\nmodern REs (roughly those of egrep; POSIX.2 calls these \"extended\" REs)\nand  obsolete REs (roughly those of ed(1); POSIX.2 \"basic\" REs).  Obso-\nlete REs mostly exist for backward compatibility in some old  programs;\nthey  will  be discussed at the end.  POSIX.2 leaves some aspects of RE\nsyntax and semantics open; \"(!)\" marks decisions on these aspects  that\nmay not be fully portable to other POSIX.2 implementations.\n\nA (modern) RE is one(!) or more nonempty(!) branches, separated by '|'.\nIt matches anything that matches one of the branches.\n\nA branch is one(!) or more pieces, concatenated.  It  matches  a  match\nfor the first, followed by a match for the second, and so on.\n\nA  piece  is an atom possibly followed by a single(!) '*', '+', '?', or\nbound.  An atom followed by '*' matches a sequence of 0 or more matches\nof  the  atom.  An atom followed by '+' matches a sequence of 1 or more\nmatches of the atom.  An atom followed by '?' matches a sequence  of  0\nor 1 matches of the atom.\n\nA  bound  is '{' followed by an unsigned decimal integer, possibly fol-\nlowed by ',' possibly followed by another unsigned decimal integer, al-\nways  followed  by '}'.  The integers must lie between 0 and REDUPMAX\n(255(!)) inclusive, and if there are two of them, the first may not ex-\nceed  the second.  An atom followed by a bound containing one integer i\nand no comma matches a sequence of exactly i matches of the  atom.   An\natom followed by a bound containing one integer i and a comma matches a\nsequence of i or more matches of the atom.  An atom followed by a bound\ncontaining  two integers i and j matches a sequence of i through j (in-\nclusive) matches of the atom.\n\nAn atom is a regular expression enclosed in \"()\" (matching a match  for\nthe  regular  expression),  an  empty  set  of  \"()\" (matching the null\nstring)(!), a bracket expression (see below), '.' (matching any  single\ncharacter),  '^' (matching the null string at the beginning of a line),\n'$' (matching the null string at the end of a line), a '\\' followed  by\none  of the characters \"^.[$()|*+?{\\\" (matching that character taken as\nan ordinary character),  a  '\\'  followed  by  any  other  character(!)\n(matching  that character taken as an ordinary character, as if the '\\'\nhad not been present(!)), or a single character with no other  signifi-\ncance  (matching  that character).  A '{' followed by a character other\nthan a digit is an ordinary character, not the beginning of a bound(!).\nIt is illegal to end an RE with '\\'.\n\nA bracket expression is a list of characters enclosed in \"[]\".  It nor-\nmally matches any single character from the list (but see  below).   If\nthe  list begins with '^', it matches any single character (but see be-\nlow) not from the rest of the list.  If two characters in the list  are\nseparated  by  '-',  this is shorthand for the full range of characters\nbetween those two (inclusive) in the collating sequence,  for  example,\n\"[0-9]\"  in  ASCII matches any decimal digit.  It is illegal(!) for two\nranges to share an endpoint, for example,  \"a-c-e\".   Ranges  are  very\ncollating-sequence-dependent,  and portable programs should avoid rely-\ning on them.\n\nTo include a literal ']' in the list, make it the first character (fol-\nlowing a possible '^').  To include a literal '-', make it the first or\nlast character, or the second endpoint of a range.  To  use  a  literal\n'-'  as  the first endpoint of a range, enclose it in \"[.\" and \".]\"  to\nmake it a collating element (see below).  With the exception  of  these\nand  some  combinations using '[' (see next paragraphs), all other spe-\ncial characters, including '\\', lose their special significance  within\na bracket expression.\n\nWithin a bracket expression, a collating element (a character, a multi-\ncharacter sequence that collates as if it were a single character, or a\ncollating-sequence  name  for  either) enclosed in \"[.\" and \".]\" stands\nfor the sequence of characters of that collating element.  The sequence\nis  a  single  element of the bracket expression's list.  A bracket ex-\npression containing a multicharacter collating element can  thus  match\nmore  than  one  character,  for example, if the collating sequence in-\ncludes a \"ch\" collating element, then the RE \"[[.ch.]]*c\"  matches  the\nfirst five characters of \"chchcc\".\n\nWithin  a  bracket expression, a collating element enclosed in \"[=\" and\n\"=]\" is an equivalence class, standing for the sequences of  characters\nof  all  collating  elements  equivalent to that one, including itself.\n(If there are no other equivalent collating elements, the treatment  is\nas  if the enclosing delimiters were \"[.\" and \".]\".)  For example, if o\nand ^  are  the  members  of  an  equivalence  class,  then  \"[[=o=]]\",\n\"[[=^=]]\",  and  \"[o^]\"  are  all synonymous.  An equivalence class may\nnot(!) be an endpoint of a range.\n\nWithin a bracket expression, the name of a character class enclosed  in\n\"[:\"  and  \":]\" stands for the list of all characters belonging to that\nclass.  Standard character class names are:\n\nalnum   digit   punct\nalpha   graph   space\nblank   lower   upper\ncntrl   print   xdigit\n\nThese stand for the character classes defined in wctype(3).   A  locale\nmay  provide  others.  A character class may not be used as an endpoint\nof a range.\n\nIn the event that an RE could match more than one substring of a  given\nstring, the RE matches the one starting earliest in the string.  If the\nRE could match more than one  substring  starting  at  that  point,  it\nmatches  the  longest.   Subexpressions also match the longest possible\nsubstrings, subject to the constraint that the whole match be  as  long\nas possible, with subexpressions starting earlier in the RE taking pri-\nority over ones starting later.  Note that higher-level  subexpressions\nthus take priority over their lower-level component subexpressions.\n\nMatch  lengths  are  measured in characters, not collating elements.  A\nnull string is considered longer than no match at  all.   For  example,\n\"bb*\"    matches    the    three    middle   characters   of   \"abbbc\",\n\"(wee|week)(knights|nights)\"  matches  all  ten  characters  of  \"week-\nnights\",  when \"(.*).*\" is matched against \"abc\" the parenthesized sub-\nexpression matches all three characters, and when  \"(a*)*\"  is  matched\nagainst  \"bc\"  both  the  whole  RE and the parenthesized subexpression\nmatch the null string.\n\nIf case-independent matching is specified, the effect is much as if all\ncase  distinctions  had vanished from the alphabet.  When an alphabetic\nthat exists in multiple cases appears as an ordinary character  outside\na  bracket expression, it is effectively transformed into a bracket ex-\npression containing both cases, for example, 'x' becomes \"[xX]\".   When\nit appears inside a bracket expression, all case counterparts of it are\nadded to the bracket expression, so that, for  example,  \"[x]\"  becomes\n\"[xX]\" and \"[^x]\" becomes \"[^xX]\".\n\nNo  particular  limit is imposed on the length of REs(!).  Programs in-\ntended to be portable should not employ REs longer than 256  bytes,  as\nan  implementation  can refuse to accept such REs and remain POSIX-com-\npliant.\n\nObsolete (\"basic\") regular  expressions  differ  in  several  respects.\n'|',  '+',  and  '?' are ordinary characters and there is no equivalent\nfor their functionality.  The delimiters for bounds are \"\\{\" and  \"\\}\",\nwith  '{'  and  '}' by themselves ordinary characters.  The parentheses\nfor nested subexpressions are \"\\(\" and \"\\)\", with '(' and ')' by  them-\nselves ordinary characters.  '^' is an ordinary character except at the\nbeginning of the RE or(!) the beginning of a  parenthesized  subexpres-\nsion,  '$'  is  an ordinary character except at the end of the RE or(!)\nthe end of a parenthesized subexpression, and '*' is an ordinary  char-\nacter  if  it  appears at the beginning of the RE or the beginning of a\nparenthesized subexpression (after a possible leading '^').\n\nFinally, there is one new type of atom, a back reference: '\\'  followed\nby  a  nonzero  decimal digit d matches the same sequence of characters\nmatched by the dth parenthesized  subexpression  (numbering  subexpres-\nsions by the positions of their opening parentheses, left to right), so\nthat, for example, \"\\([bc]\\)\\1\" matches \"bb\" or \"cc\" but not \"bc\".\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Having two kinds of REs is a botch.\n\nThe current POSIX.2 spec says that ')' is an ordinary character in  the\nabsence  of  an  unmatched  '(';  this was an unintentional result of a\nwording error, and change is likely.  Avoid relying on it.\n\nBack references are a dreadful botch, posing major problems  for  effi-\ncient  implementations.   They  are also somewhat vaguely defined (does\n\"a\\(\\(b\\)*\\2\\)*d\" match \"abbbd\"?).  Avoid using them.\n\nPOSIX.2's specification of case-independent  matching  is  vague.   The\n\"one  case implies all cases\" definition given above is current consen-\nsus among implementors as to the right interpretation.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "This page was taken from Henry Spencer's regex package.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "grep(1), regex(3)\n\nPOSIX.2, section 2.8 (Regular Expression Notation).\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This page is part of release 5.10 of the Linux  man-pages  project.   A\ndescription  of  the project, information about reporting bugs, and the\nlatest    version    of    this    page,    can     be     found     at\nhttps://www.kernel.org/doc/man-pages/.\n\n2020-08-13                          REGEX(7)",
            "subsections": []
        }
    },
    "summary": "regex - POSIX.2 regular expressions",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "grep",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/grep/1/json"
        },
        {
            "name": "regex",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/regex/3/json"
        }
    ]
}