tags:

views:

95

answers:

1

Hello, I would like to find all comment blocks(/*...*/) but the function g_regex_match_full always returns true. Here is the code :

// Create the regex.
start_block_comment_regex = g_regex_new("/\*.*\*/", G_REGEX_OPTIMIZE, 0, &regex_error);

//Search the regex;
if(TRUE == g_regex_match_full(start_block_comment_regex, current_line, -1, 0, 0, &match_info, &regex_error))
{
}
+1  A: 

You're not using the pattern you think you are. You have to escape backslashes in strings in C:

comment_regex = g_regex_new("/\\*.*\\*/", G_REGEX_OPTIMIZE, 0, &regex_error);

I'm surprised you don't get compiler warnings about "undefined escape sequence \*" from your current code. I'm also surprised you didn't get errors from glib there - the pattern you effectively used was probably /*.**/, which doesn't make much sense. (Did you check regex_error? Obviously didn't if that's the full code...)

Jefromi
Yes, you are right. It's a stupid mistake.
Sebastian