c - regex.h: print the subexpression -


I want to remove a substrings from my expression using the regex.h library in C. Here is the code

  #include & lt; Regex.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Int main (zero) {regex_t preg; Char * string = "Random_ddName: cateof: name_Random"; Four * pattern = ". * Name: \\ (. * \\): name. *"; Int rc; Size_t nmatch = 1; Regmatch_t pmatch [1]; If (0! = (RC = ReggP (and preg, pattern, 0)) {printf ("regcomp () failed, non-returned (% d) \ n", RC); Exhaust (EXIT_FAILURE); } If (0! = (RC = RezekneAk & amp; Prege, String, NMH, PMF, 0)) {Could not match '% s' from 'printf' ('% s', returning to% d. \ N "string, pattern, rc);} Else {printf (" with a full expression, "" a matched substrument \ "%. * S \" status is found at% d to% d. \ N " , Pmatch [0] .rm_eo - pmatch [0] .rm_so, and string [pmatch [0]. Rm_so], pmatch [0]. Rm_so, pmatch [0] .rm_eo - 1);} Regfree (& amp; preg) ); Return 0;}  

I want to remove the "cateof" string, but I want to make sure that Between the name of the triangle: and: the name: Caitiff is random, it changes dynamically and it is the only part which I want. How can I get it once? Do I need a backcrany Is it possible to use? nmatch = 2 ,

so that the whole match in pmatch [0] and pmatch [1] you want subpants.

Required code changes:

  size_t nmatch = 2; Regmatch_t pmatch [2];  

and

  ... pmatch [1]. Rm_eo - pmatch [1]. Rm_so, and string [pmatch [1]. Rm_so], Pmatch [1]. Rm_so, pmatch [1]. Rm_eo - 1); ...  

Comments