I have been busy recently, and I have never written a blog. I finally got my own time yesterday and continue to learn ~~
For details about the c Regular Expression, man RegEx can see a lot, just paste the code here and describe what you need to pay attention:
1. If you need to output special characters, you need to reverse the meaning twice.
2. Viewing various statuses is a good habit.
3. Match [0] is the original data. If you want to find the matching result, it starts with match [1 ].
Code ~~
# Include <stdio. h> <br/> # include <RegEx. h> <br/> # include <sys/types. h> <br/> # include <string> <br/> int main () <br/> {<br/> regex_t reg; <br/> size_t error_len; <br/> int ret = 0; <br/> char Buf [1024]; <br/> const char * test = "url = [http://hit.love.wenwen.com]/n "; <br/> const char * preg = "url = //[(. *?) //] "; <Br/> If (ret = regcomp (, preg, reg_extended ))! = 0) {<br/> If (regerror (Ret, Buf, 1024) {<br/> printf ("comp Reg failed: % s/n ", buf); <br/>}< br/> return 1; <br/>}< br/> regmatch_t match [4]; <br/> If (ret = regexec (, test, 4, match, reg_notbol ))! = 0) {<br/> If (regerror (Ret, Buf, 1024) {<br/> printf ("Match Reg failed: % s/n ", buf); <br/>}< br/> return 1; <br/>}else {<br/> int Index = 1; <br/> while (Match [Index]. rm_so! =-1) {<br/> printf ("Match % d: % s/n", index, <br/> STD: string (test + match [Index]. rm_so, test + match [Index]. rm_eo ). c_str (); <br/> + index; <br/>}< br/> <br/> regfree (); <br/> return 0; <br/>}