GRegex regular expression failing to match

2012-05-14 Thread Christopher Howard
I'm trying glib's GRegex functionality for the first time, and
apparently I am doing something wrong. I have some code like so:

code:

  GError * error = NULL;

  GRegex * regex = g_regex_new (^/(d+)$, 0, 0, error);

  if (error != NULL)
{
  // ...
}

  GMatchInfo * match_info;

  g_regex_match (regex, path, 0, match_info);

  if (g_match_info_matches (match_info))
{
  gchar * word = g_match_info_fetch (match_info, 1);
  // ...
}


In my unit test, I pass in in the string /1, hoping to match and then
pull out the number. A GError is not thrown (so my GRegex is compiling),
but g_match_info_matches() is returning FALSE.

Is there anything wrong with the regexp, or perhaps my g_regex_new()
options, or anything else obvious?

-- 
frigidcode.com
indicium.us

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: GRegex regular expression failing to match

2012-05-14 Thread David Nečas
On Mon, May 14, 2012 at 01:36:02PM -0800, Christopher Howard wrote:
 Is there anything wrong with the regexp,

Sure.  Two things.  It should be

^/[0-9]+$

not

^/d+$

First, it lacks the backslash to make \d a digit atom.  But, second,
since \d matches a digit (possibly whatever Unicode may say is a digit),
not 0-9, you should really use [0-9] to match ASCII digits.

Yeti
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list