regfree() — Free memory for regular expression

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#include <regex.h>

void regfree(regex_t *preg);

General description

Frees any memory that was allocated by regcomp() to implement preg. The expression defined by preg is no longer a compiled regular or extended expression. (For a description of regular expressions, see Regular expressions.)

Example

CELEBR10
⁄* CELEBR10                                      

   This example compiles an extended regular expression and a                   
   free regular expression.                                                     

 *⁄                                                                             
#include <regex.h>                                                              
#include <locale.h>                                                             
#include <stdio.h>                                                              
#include <stdlib.h>                                                             
                                                                                
main() {                                                                        
    regex_t    preg;                                                            
    char       *pattern = ".*(simple).*";                                       
    int        rc;                                                              
                                                                                
    if ((rc = regcomp(&preg, pattern, REG_EXTENDED)) != 0) {                    
       printf("regcomp() failed, returning nonzero (%d)\n", rc);                
       exit(1);                                                                 
    }                                                                           
                                                                                
    regfree(&preg);                                                             
}                                                                               

Related information