I have following code:
gchar **split = g_strsplit(str, "\n", 0);
gchar **pointer = NULL;
GRegex *line_regex = NULL;
GMatchInfo *info = NULL;
line_regex = g_regex_new("^.*:(\\d+):.*$", 0, 0, NULL);
gtk_list_store_clear(store);
gtk_list_store_clear(store);
for (pointer = split; *pointer; pointer++)
if (strlen(*pointer)){
gchar *word = "";
if (line_regex && g_regex_match(line_regex, *pointer, 0, &info)){
if (g_match_info_matches(info)){
word = g_match_info_fetch(info, 0);
}
}
gtk_list_store_insert_with_values(store, NULL, -1, 0, word, 1, *pointer, -1);
}
I would like to get value inside the group, which means for following string:
some-test:56:some-other-text
I would like to get 56. I have no idea how gtk works, so I am a little blind here and I haven’t found anything in docs. In python I would use groups methods, so here I would need something similar. Could you advise me how to get it?
I found useful information at gnome.org’s g-match-info-fetch page which indicates that
g_match_info_fetch(info, 0)returns the whole match, which for your^ ... $regex is the whole line. The code shown below (which is like your code, except I replacedgtk_list_storestuff with a printf) illustrates thatg_match_info_fetch(info, 1)returns the field you want. The code displays the following 3 lines:Here’s the code: