You can use regex.h directly to support regular expressions under Linux.
Android also has this header file, which can be thought of as supported by Android.
#include <sys/types.h>
#include <regex.h>
int Regcomp (regex_t *preg, const char *regex, int cflags);
int regexec (const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
size_t regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
void RegFree (regex_t *preg);
The Rm_so is the match string start offset (start offset), and the rm_eo is the terminating offset of the matching string (end offset).
typedef struct {
regoff_t Rm_so;
regoff_t Rm_eo;
} regmatch_t;
1#include <stdio.h>2#include <regex.h>3#include <string.h>4 5 intMainvoid)6 {7 Const Char*str ="aabbccdd.com";8 Const Char*pattern ="^(.+?) \\.com$";9 regex_t reg;Tenregmatch_t match[Ten]; One A intRET =0; -ret = Regcomp (®, pattern, reg_extended |reg_newline); - if(Ret! =0) theprintf"error\n"); - Else - { -ret = regexec (®, str,Ten, Match,0); + if(Ret! =Reg_nomatch) - { + intLen = match[1].rm_eo-match[1].rm_so; A Charbuf[1024x768] = {0}; atmemcpy (buf, str + match[1].rm_so, Len); -printf"final BUF%s\n", buf); - } - } -RegFree (®); - return 0; in}
The regmatch_t array is used to store matching results, the reason for the array is actually to match the group, its rules and Java and other implementations are consistent, if the match succeeds, the array of [0] is the entire matching string, that is, group (0), the other for each match to the group.
Man regex
The regex that comes with Linux