#include <gtk/gtk.h>

#define NUMBER_0_255 "(25[0-5]|2[0-4][0-9]|[01]?([0-9]){1,2})"
#define IPV4_REGEX "^(" NUMBER_0_255 "\\.){3}" NUMBER_0_255 "$"

static void
on_entry_match_changed (GtkEntry *entry, gpointer data)
{
	g_print ("Text matches filter: %s\n",
		 (gtk_entry_text_matches_filter (entry)) ? "yes" : "no");
}

int
main (int argc, gchar *argv[])
{
	GtkWidget *window, *entry;
	GRegex *regex;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	entry = gtk_entry_new ();
	regex = g_regex_new (IPV4_REGEX, 0, 0, NULL);
	g_object_set (entry, "filter-regex", regex, NULL);

	g_signal_connect (entry, "match-changed",
			  G_CALLBACK (on_entry_match_changed), NULL);

	gtk_container_add (GTK_CONTAINER (window), entry);
	gtk_widget_show_all (window);

	gtk_main ();

	return 0;
}
