gregex.h File Reference

__G_REGEX_H__

Enum GRegexError

EnumeratorValueDescription
G_REGEX_ERROR_COMPILE
G_REGEX_ERROR_OPTIMIZE
G_REGEX_ERROR_REPLACE
G_REGEX_ERROR_MATCH
G_REGEX_ERROR_INTERNAL
G_REGEX_ERROR_STRAY_BACKSLASH101
G_REGEX_ERROR_MISSING_CONTROL_CHAR102
G_REGEX_ERROR_UNRECOGNIZED_ESCAPE103
G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER104
G_REGEX_ERROR_QUANTIFIER_TOO_BIG105
G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS106
G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS107
G_REGEX_ERROR_RANGE_OUT_OF_ORDER108
G_REGEX_ERROR_NOTHING_TO_REPEAT109
G_REGEX_ERROR_UNRECOGNIZED_CHARACTER112
G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS113
G_REGEX_ERROR_UNMATCHED_PARENTHESIS114
G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE115
G_REGEX_ERROR_UNTERMINATED_COMMENT118
G_REGEX_ERROR_EXPRESSION_TOO_LARGE120
G_REGEX_ERROR_MEMORY_ERROR121
G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND125
G_REGEX_ERROR_MALFORMED_CONDITION126
G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES127
G_REGEX_ERROR_ASSERTION_EXPECTED128
G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME130
G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED131
G_REGEX_ERROR_HEX_CODE_TOO_LARGE134
G_REGEX_ERROR_INVALID_CONDITION135
G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND136
G_REGEX_ERROR_INFINITE_LOOP140
G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR142
G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME143
G_REGEX_ERROR_MALFORMED_PROPERTY146
G_REGEX_ERROR_UNKNOWN_PROPERTY147
G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG148
G_REGEX_ERROR_TOO_MANY_SUBPATTERNS149
G_REGEX_ERROR_INVALID_OCTAL_VALUE151
G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE154
G_REGEX_ERROR_DEFINE_REPETION155
G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS156
G_REGEX_ERROR_MISSING_BACK_REFERENCE157

G_REGEX_ERROR

g_regex_error_quark ( void )

GQuark g_regex_error_quark(void)

Enum GRegexCompileFlags

EnumeratorValueDescription
G_REGEX_CASELESS1 << 0
G_REGEX_MULTILINE1 << 1
G_REGEX_DOTALL1 << 2
G_REGEX_EXTENDED1 << 3
G_REGEX_ANCHORED1 << 4
G_REGEX_DOLLAR_ENDONLY1 << 5
G_REGEX_UNGREEDY1 << 9
G_REGEX_RAW1 << 11
G_REGEX_NO_AUTO_CAPTURE1 << 12
G_REGEX_OPTIMIZE1 << 13
G_REGEX_DUPNAMES1 << 19
G_REGEX_NEWLINE_CR1 << 20
G_REGEX_NEWLINE_LF1 << 21
G_REGEX_NEWLINE_CRLFG_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF

Enum GRegexMatchFlags

EnumeratorValueDescription
G_REGEX_MATCH_ANCHORED1 << 4
G_REGEX_MATCH_NOTBOL1 << 7
G_REGEX_MATCH_NOTEOL1 << 8
G_REGEX_MATCH_NOTEMPTY1 << 10
G_REGEX_MATCH_PARTIAL1 << 15
G_REGEX_MATCH_NEWLINE_CR1 << 20
G_REGEX_MATCH_NEWLINE_LF1 << 21
G_REGEX_MATCH_NEWLINE_CRLFG_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF
G_REGEX_MATCH_NEWLINE_ANY1 << 22

Typedef GRegex

typedef struct _GRegexGRegex

Typedef GMatchInfo

typedef struct _GMatchInfoGMatchInfo

Typedef GRegexEvalCallback

typedef gboolean(*GRegexEvalCallback

g_regex_new ( const gchar *, GRegexCompileFlags, GRegexMatchFlags, GError ** )

IMPORT_C GRegex *g_regex_new(const gchar *pattern,
GRegexCompileFlagscompile_options,
GRegexMatchFlagsmatch_options,
GError **error
)

g_regex_new: : the regular expression : compile options for the regular expression, or 0 : match options for the regular expression, or 0 : return location for a GError

Compiles the regular expression to an internal form, and does the initial setup of the GRegex structure.

Returns: a GRegex structure. Call g_regex_unref() when you are done with it

Since: 2.14

g_regex_ref ( GRegex * )

IMPORT_C GRegex *g_regex_ref(GRegex *regex)

g_regex_ref: : a GRegex

Increases reference count of by 1.

Returns:

Since: 2.14

g_regex_unref ( GRegex * )

IMPORT_C voidg_regex_unref(GRegex *regex)

g_regex_unref: : a GRegex

Decreases reference count of by 1. When reference count drops to zero, it frees all the memory associated with the regex structure.

Since: 2.14

g_regex_get_pattern ( const GRegex * )

IMPORT_C const gchar *g_regex_get_pattern(const GRegex *regex)

g_regex_get_pattern: : a GRegex structure

Gets the pattern string associated with , i.e. a copy of the string passed to g_regex_new().

Returns: the pattern of

Since: 2.14

g_regex_get_max_backref ( const GRegex * )

IMPORT_C gintg_regex_get_max_backref(const GRegex *regex)

g_regex_get_max_backref: : a GRegex

Returns the number of the highest back reference in the pattern, or 0 if the pattern does not contain back references.

Returns: the number of the highest back reference

Since: 2.14

g_regex_get_capture_count ( const GRegex * )

IMPORT_C gintg_regex_get_capture_count(const GRegex *regex)

g_regex_get_capture_count: : a GRegex

Returns the number of capturing subpatterns in the pattern.

Returns: the number of capturing subpatterns

Since: 2.14

g_regex_get_string_number ( const GRegex *, const gchar * )

IMPORT_C gintg_regex_get_string_number(const GRegex *regex,
const gchar *name
)

g_regex_escape_string ( const gchar *, gint )

IMPORT_C gchar *g_regex_escape_string(const gchar *string,
gintlength
)

g_regex_escape_string: : the string to escape : the length of , or -1 if is nul-terminated

Escapes the special characters used for regular expressions in , for instance "a.b*c" becomes "a\.b\*c". This function is useful to dynamically generate regular expressions.

can contain nul characters that are replaced with "\0", in this case remember to specify the correct length of in .

Returns: a newly-allocated escaped string

Since: 2.14

g_regex_match_simple ( const gchar *, const gchar *, GRegexCompileFlags, GRegexMatchFlags )

IMPORT_C gbooleang_regex_match_simple(const gchar *pattern,
const gchar *string,
GRegexCompileFlagscompile_options,
GRegexMatchFlagsmatch_options
)

g_regex_match_simple: : the regular expression : the string to scan for matches : compile options for the regular expression, or 0 : match options, or 0

Scans for a match in for .

This function is equivalent to g_regex_match() but it does not require to compile the pattern with g_regex_new(), avoiding some lines of code when you need just to do a match without extracting substrings, capture counts, and so on.

If this function is to be called on the same more than once, it's more efficient to compile the pattern once with g_regex_new() and then use g_regex_match().

Returns: TRUE if the string matched, FALSE otherwise

Since: 2.14

g_regex_match ( const GRegex *, const gchar *, GRegexMatchFlags, GMatchInfo ** )

IMPORT_C gbooleang_regex_match(const GRegex *regex,
const gchar *string,
GRegexMatchFlagsmatch_options,
GMatchInfo **match_info
)

g_regex_match: : a GRegex structure from g_regex_new() : the string to scan for matches : match options : pointer to location where to store the GMatchInfo, or NULL if you do not need it

Scans for a match in string for the pattern in . The are combined with the match options specified when the structure was created, letting you have more flexibility in reusing GRegex structures.

A GMatchInfo structure, used to get information on the match, is stored in if not NULL. Note that if is not NULL then it is created even if the function returns FALSE, i.e. you must free it regardless if regular expression actually matched.

To retrieve all the non-overlapping matches of the pattern in string you can use g_match_info_next().

|[ static void print_uppercase_words (const gchar *string) { / Print all uppercase-only words. / GRegex *regex; GMatchInfo *match_info;   regex = g_regex_new ("[A-Z]+", 0, 0, NULL); g_regex_match (regex, string, 0, &match_info); while (g_match_info_matches (match_info)) { gchar *word = g_match_info_fetch (match_info, 0); g_print ("Found: %s\n", word); g_free (word); g_match_info_next (match_info, NULL); } g_match_info_free (match_info); g_regex_unref (regex); } ]|

is not copied and is used in GMatchInfo internally. If you use any GMatchInfo method (except g_match_info_free()) after freeing or modifying then the behaviour is undefined.

Returns: TRUE is the string matched, FALSE otherwise

Since: 2.14

g_regex_match_full ( const GRegex *, const gchar *, gssize, gint, GRegexMatchFlags, GMatchInfo **, GError ** )

IMPORT_C gbooleang_regex_match_full(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
GRegexMatchFlagsmatch_options,
GMatchInfo **match_info,
GError **error
)

g_regex_match_full: : a GRegex structure from g_regex_new() : the string to scan for matches : the length of , or -1 if is nul-terminated : starting index of the string to match : match options : pointer to location where to store the GMatchInfo, or NULL if you do not need it : location to store the error occuring, or NULL to ignore errors

Scans for a match in string for the pattern in . The are combined with the match options specified when the structure was created, letting you have more flexibility in reusing GRegex structures.

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

A GMatchInfo structure, used to get information on the match, is stored in if not NULL. Note that if is not NULL then it is created even if the function returns FALSE, i.e. you must free it regardless if regular expression actually matched.

is not copied and is used in GMatchInfo internally. If you use any GMatchInfo method (except g_match_info_free()) after freeing or modifying then the behaviour is undefined.

To retrieve all the non-overlapping matches of the pattern in string you can use g_match_info_next().

|[ static void print_uppercase_words (const gchar *string) { / Print all uppercase-only words. / GRegex *regex; GMatchInfo *match_info; GError *error = NULL;   regex = g_regex_new ("[A-Z]+", 0, 0, NULL); g_regex_match_full (regex, string, -1, 0, 0, &match_info, &error); while (g_match_info_matches (match_info)) { gchar *word = g_match_info_fetch (match_info, 0); g_print ("Found: %s\n", word); g_free (word); g_match_info_next (match_info, &error); } g_match_info_free (match_info); g_regex_unref (regex); if (error != NULL) { g_printerr ("Error while matching: %s\n", error->message); g_error_free (error); } } ]|

Returns: TRUE is the string matched, FALSE otherwise

Since: 2.14

g_regex_match_all ( const GRegex *, const gchar *, GRegexMatchFlags, GMatchInfo ** )

IMPORT_C gbooleang_regex_match_all(const GRegex *regex,
const gchar *string,
GRegexMatchFlagsmatch_options,
GMatchInfo **match_info
)

g_regex_match_all: : a GRegex structure from g_regex_new() : the string to scan for matches : match options : pointer to location where to store the GMatchInfo, or NULL if you do not need it

Using the standard algorithm for regular expression matching only the longest match in the string is retrieved. This function uses a different algorithm so it can retrieve all the possible matches. For more documentation see g_regex_match_all_full().

A GMatchInfo structure, used to get information on the match, is stored in if not NULL. Note that if is not NULL then it is created even if the function returns FALSE, i.e. you must free it regardless if regular expression actually matched.

is not copied and is used in GMatchInfo internally. If you use any GMatchInfo method (except g_match_info_free()) after freeing or modifying then the behaviour is undefined.

Returns: TRUE is the string matched, FALSE otherwise

Since: 2.14

g_regex_match_all_full ( const GRegex *, const gchar *, gssize, gint, GRegexMatchFlags, GMatchInfo **, GError ** )

IMPORT_C gbooleang_regex_match_all_full(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
GRegexMatchFlagsmatch_options,
GMatchInfo **match_info,
GError **error
)

g_regex_match_all_full: : a GRegex structure from g_regex_new() : the string to scan for matches : the length of , or -1 if is nul-terminated : starting index of the string to match : match options : pointer to location where to store the GMatchInfo, or NULL if you do not need it : location to store the error occuring, or NULL to ignore errors

Using the standard algorithm for regular expression matching only the longest match in the string is retrieved, it is not possibile to obtain all the available matches. For instance matching "&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;" you get "&lt;a&gt; &lt;b&gt; &lt;c&gt;".

This function uses a different algorithm (called DFA, i.e. deterministic finite automaton), so it can retrieve all the possible matches, all starting at the same point in the string. For instance matching "&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;" you would obtain three matches: "&lt;a&gt; &lt;b&gt; &lt;c&gt;", "&lt;a&gt; &lt;b&gt;" and "&lt;a&gt;".

The number of matched strings is retrieved using g_match_info_get_match_count(). To obtain the matched strings and their position you can use, respectively, g_match_info_fetch() and g_match_info_fetch_pos(). Note that the strings are returned in reverse order of length; that is, the longest matching string is given first.

Note that the DFA algorithm is slower than the standard one and it is not able to capture substrings, so backreferences do not work.

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

A GMatchInfo structure, used to get information on the match, is stored in if not NULL. Note that if is not NULL then it is created even if the function returns FALSE, i.e. you must free it regardless if regular expression actually matched.

is not copied and is used in GMatchInfo internally. If you use any GMatchInfo method (except g_match_info_free()) after freeing or modifying then the behaviour is undefined.

Returns: TRUE is the string matched, FALSE otherwise

Since: 2.14

g_regex_split_simple ( const gchar *, const gchar *, GRegexCompileFlags, GRegexMatchFlags )

IMPORT_C gchar **g_regex_split_simple(const gchar *pattern,
const gchar *string,
GRegexCompileFlagscompile_options,
GRegexMatchFlagsmatch_options
)

g_regex_split_simple: : the regular expression : the string to scan for matches : compile options for the regular expression, or 0 : match options, or 0

Breaks the string on the pattern, and returns an array of the tokens. If the pattern contains capturing parentheses, then the text for each of the substrings will also be returned. If the pattern does not match anywhere in the string, then the whole string is returned as the first token.

This function is equivalent to g_regex_split() but it does not require to compile the pattern with g_regex_new(), avoiding some lines of code when you need just to do a split without extracting substrings, capture counts, and so on.

If this function is to be called on the same more than once, it's more efficient to compile the pattern once with g_regex_new() and then use g_regex_split().

As a special case, the result of splitting the empty string "" is an empty vector, not a vector containing a single string. The reason for this special case is that being able to represent a empty vector is typically more useful than consistent handling of empty elements. If you do need to represent empty elements, you'll need to check for the empty string before calling this function.

A pattern that can match empty strings splits into separate characters wherever it matches the empty string between characters. For example splitting "ab c" using as a separator "\s*", you will get "a", "b" and "c".

Returns: a NULL-terminated array of strings. Free it using g_strfreev()

Since: 2.14

g_regex_split ( const GRegex *, const gchar *, GRegexMatchFlags )

IMPORT_C gchar **g_regex_split(const GRegex *regex,
const gchar *string,
GRegexMatchFlagsmatch_options
)

g_regex_split: : a GRegex structure : the string to split with the pattern : match time option flags

Breaks the string on the pattern, and returns an array of the tokens. If the pattern contains capturing parentheses, then the text for each of the substrings will also be returned. If the pattern does not match anywhere in the string, then the whole string is returned as the first token.

As a special case, the result of splitting the empty string "" is an empty vector, not a vector containing a single string. The reason for this special case is that being able to represent a empty vector is typically more useful than consistent handling of empty elements. If you do need to represent empty elements, you'll need to check for the empty string before calling this function.

A pattern that can match empty strings splits into separate characters wherever it matches the empty string between characters. For example splitting "ab c" using as a separator "\s*", you will get "a", "b" and "c".

Returns: a NULL-terminated gchar ** array. Free it using g_strfreev()

Since: 2.14

g_regex_split_full ( const GRegex *, const gchar *, gssize, gint, GRegexMatchFlags, gint, GError ** )

IMPORT_C gchar **g_regex_split_full(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
GRegexMatchFlagsmatch_options,
gintmax_tokens,
GError **error
)

g_regex_split_full: : a GRegex structure : the string to split with the pattern : the length of , or -1 if is nul-terminated : starting index of the string to match : match time option flags : the maximum number of tokens to split into. If this is less than 1, the string is split completely : return location for a GError

Breaks the string on the pattern, and returns an array of the tokens. If the pattern contains capturing parentheses, then the text for each of the substrings will also be returned. If the pattern does not match anywhere in the string, then the whole string is returned as the first token.

As a special case, the result of splitting the empty string "" is an empty vector, not a vector containing a single string. The reason for this special case is that being able to represent a empty vector is typically more useful than consistent handling of empty elements. If you do need to represent empty elements, you'll need to check for the empty string before calling this function.

A pattern that can match empty strings splits into separate characters wherever it matches the empty string between characters. For example splitting "ab c" using as a separator "\s*", you will get "a", "b" and "c".

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

Returns: a NULL-terminated gchar ** array. Free it using g_strfreev()

Since: 2.14

g_regex_replace ( const GRegex *, const gchar *, gssize, gint, const gchar *, GRegexMatchFlags, GError ** )

IMPORT_C gchar *g_regex_replace(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
const gchar *replacement,
GRegexMatchFlagsmatch_options,
GError **error
)

g_regex_replace: : a GRegex structure : the string to perform matches against : the length of , or -1 if is nul-terminated : starting index of the string to match : text to replace each match with : options for the match : location to store the error occuring, or NULL to ignore errors

Replaces all occurrences of the pattern in with the replacement text. Backreferences of the form '' or '<number>' in the replacement text are interpolated by the number-th captured subexpression of the match, '<name>' refers to the captured subexpression with the given name. '\0' refers to the complete match, but '\0' followed by a number is the octal representation of a character. To include a literal '\' in the replacement, write '\'. There are also escapes that changes the case of the following text:

<variablelist> <varlistentry> <listitem>

Convert to lower case the next character

</listitem> </varlistentry> <varlistentry> <listitem>

Convert to upper case the next character

</listitem> </varlistentry> <varlistentry> <listitem>

Convert to lower case till

</listitem> </varlistentry> <varlistentry> <listitem>

Convert to upper case till

</listitem> </varlistentry> <varlistentry> <listitem>

End case modification

</listitem> </varlistentry> </variablelist>

If you do not need to use backreferences use g_regex_replace_literal().

The string must be UTF-8 encoded even if G_REGEX_RAW was passed to g_regex_new(). If you want to use not UTF-8 encoded stings you can use g_regex_replace_literal().

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

Returns: a newly allocated string containing the replacements

Since: 2.14

g_regex_replace_literal ( const GRegex *, const gchar *, gssize, gint, const gchar *, GRegexMatchFlags, GError ** )

IMPORT_C gchar *g_regex_replace_literal(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
const gchar *replacement,
GRegexMatchFlagsmatch_options,
GError **error
)

g_regex_replace_literal: : a GRegex structure : the string to perform matches against : the length of , or -1 if is nul-terminated : starting index of the string to match : text to replace each match with : options for the match : location to store the error occuring, or NULL to ignore errors

Replaces all occurrences of the pattern in with the replacement text. is replaced literally, to include backreferences use g_regex_replace().

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

Returns: a newly allocated string containing the replacements

Since: 2.14

g_regex_replace_eval ( const GRegex *, const gchar *, gssize, gint, GRegexMatchFlags, GRegexEvalCallback, gpointer, GError ** )

IMPORT_C gchar *g_regex_replace_eval(const GRegex *regex,
const gchar *string,
gssizestring_len,
gintstart_position,
GRegexMatchFlagsmatch_options,
GRegexEvalCallbackeval,
gpointeruser_data,
GError **error
)

g_regex_replace_eval: : a GRegex structure from g_regex_new() : string to perform matches against : the length of , or -1 if is nul-terminated : starting index of the string to match : options for the match : a function to call for each match : user data to pass to the function : location to store the error occuring, or NULL to ignore errors

Replaces occurrences of the pattern in regex with the output of for that occurrence.

Setting differs from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern that begins with any kind of lookbehind assertion, such as "\b".

The following example uses g_regex_replace_eval() to replace multiple strings at once: |[ static gboolean eval_cb (const GMatchInfo *info, GString *res, gpointer data) { gchar *match; gchar *r;

match = g_match_info_fetch (info, 0); r = g_hash_table_lookup ((GHashTable *)data, match); g_string_append (res, r); g_free (match);

return FALSE; }

/ ... /

GRegex *reg; GHashTable *h; gchar *res;

h = g_hash_table_new (g_str_hash, g_str_equal);

g_hash_table_insert (h, "1", "ONE"); g_hash_table_insert (h, "2", "TWO"); g_hash_table_insert (h, "3", "THREE"); g_hash_table_insert (h, "4", "FOUR");

reg = g_regex_new ("1|2|3|4", 0, 0, NULL); res = g_regex_replace_eval (reg, text, -1, 0, 0, eval_cb, h, NULL); g_hash_table_destroy (h);

/ ... / ]|

Returns: a newly allocated string containing the replacements

Since: 2.14

g_regex_check_replacement ( const gchar *, gboolean *, GError ** )

IMPORT_C gbooleang_regex_check_replacement(const gchar *replacement,
gboolean *has_references,
GError **error
)

g_regex_check_replacement: : the replacement string : location to store information about references in or NULL : location to store error

Checks whether is a valid replacement string (see g_regex_replace()), i.e. that all escape sequences in it are valid.

If is not NULL then is checked for pattern references. For instance, replacement text 'foo' does not contain references and may be evaluated without information about actual match, but '\0\1' (whole match followed by first subpattern) requires valid GMatchInfo object.

Returns: whether is a valid replacement string

Since: 2.14

g_match_info_get_regex ( const GMatchInfo * )

IMPORT_C GRegex *g_match_info_get_regex(const GMatchInfo *match_info)

g_match_info_get_regex: : a GMatchInfo

Returns GRegex object used in . It belongs to Glib and must not be freed. Use g_regex_ref() if you need to keep it after you free object.

Returns: GRegex object used in

Since: 2.14

g_match_info_get_string ( const GMatchInfo * )

IMPORT_C const gchar *g_match_info_get_string(const GMatchInfo *match_info)

g_match_info_get_string: : a GMatchInfo

Returns the string searched with . This is the string passed to g_regex_match() or g_regex_replace() so you may not free it before calling this function.

Returns: the string searched with

Since: 2.14

g_match_info_free ( GMatchInfo * )

IMPORT_C voidg_match_info_free(GMatchInfo *match_info)

g_match_info_free: : a GMatchInfo

Frees all the memory associated with the GMatchInfo structure.

Since: 2.14

g_match_info_next ( GMatchInfo *, GError ** )

IMPORT_C gbooleang_match_info_next(GMatchInfo *match_info,
GError **error
)

g_match_info_next: : a GMatchInfo structure : location to store the error occuring, or NULL to ignore errors

Scans for the next match using the same parameters of the previous call to g_regex_match_full() or g_regex_match() that returned .

The match is done on the string passed to the match function, so you cannot free it before calling this function.

Returns: TRUE is the string matched, FALSE otherwise

Since: 2.14

g_match_info_matches ( const GMatchInfo * )

IMPORT_C gbooleang_match_info_matches(const GMatchInfo *match_info)

g_match_info_matches: : a GMatchInfo structure

Returns whether the previous match operation succeeded.

Returns: TRUE if the previous match operation succeeded, FALSE otherwise

Since: 2.14

g_match_info_get_match_count ( const GMatchInfo * )

IMPORT_C gintg_match_info_get_match_count(const GMatchInfo *match_info)

g_match_info_get_match_count: : a GMatchInfo structure

Retrieves the number of matched substrings (including substring 0, that is the whole matched text), so 1 is returned if the pattern has no substrings in it and 0 is returned if the match failed.

If the last match was obtained using the DFA algorithm, that is using g_regex_match_all() or g_regex_match_all_full(), the retrieved count is not that of the number of capturing parentheses but that of the number of matched substrings.

Returns: Number of matched substrings, or -1 if an error occurred

Since: 2.14

g_match_info_is_partial_match ( const GMatchInfo * )

IMPORT_C gbooleang_match_info_is_partial_match(const GMatchInfo *match_info)

g_match_info_is_partial_match: : a GMatchInfo structure

Usually if the string passed to g_regex_match*() matches as far as it goes, but is too short to match the entire pattern, FALSE is returned. There are circumstances where it might be helpful to distinguish this case from other cases in which there is no match.

Consider, for example, an application where a human is required to type in data for a field with specific formatting requirements. An example might be a date in the form ddmmmyy, defined by the pattern "^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$". If the application sees the user s keystrokes one by one, and can check that what has been typed so far is potentially valid, it is able to raise an error as soon as a mistake is made.

GRegex supports the concept of partial matching by means of the G_REGEX_MATCH_PARTIAL flag. When this is set the return code for g_regex_match() or g_regex_match_full() is, as usual, TRUE for a complete match, FALSE otherwise. But, when these functions return FALSE, you can check if the match was partial calling g_match_info_is_partial_match().

When using partial matching you cannot use g_match_info_fetch*().

Because of the way certain internal optimizations are implemented the partial matching algorithm cannot be used with all patterns. So repeated single characters such as "a{2,4}" and repeated single meta-sequences such as "\d+" are not permitted if the maximum number of occurrences is greater than one. Optional items such as "\d?" (where the maximum is one) are permitted. Quantifiers with any values are permitted after parentheses, so the invalid examples above can be coded thus "(a){2,4}" and "(\d)+". If G_REGEX_MATCH_PARTIAL is set for a pattern that does not conform to the restrictions, matching functions return an error.

Returns: TRUE if the match was partial, FALSE otherwise

Since: 2.14

g_match_info_expand_references ( const GMatchInfo *, const gchar *, GError ** )

IMPORT_C gchar *g_match_info_expand_references(const GMatchInfo *match_info,
const gchar *string_to_expand,
GError **error
)

g_match_info_expand_references: : a GMatchInfo or NULL : the string to expand : location to store the error occuring, or NULL to ignore errors

Returns a new string containing the text in with references and escape sequences expanded. References refer to the last match done with against and have the same syntax used by g_regex_replace().

The must be UTF-8 encoded even if G_REGEX_RAW was passed to g_regex_new().

The backreferences are extracted from the string passed to the match function, so you cannot call this function after freeing the string.

may be NULL in which case must not contain references. For instance "foo\n" does not refer to an actual pattern and '' merely will be replaced with character, while to expand "\0" (whole match) one needs the result of a match. Use g_regex_check_replacement() to find out whether contains references.

Returns: the expanded string, or NULL if an error occurred

Since: 2.14

g_match_info_fetch ( const GMatchInfo *, gint )

IMPORT_C gchar *g_match_info_fetch(const GMatchInfo *match_info,
gintmatch_num
)

g_match_info_fetch: : GMatchInfo structure : number of the sub expression

Retrieves the text matching the 'th capturing parentheses. 0 is the full text of the match, 1 is the first paren set, 2 the second, and so on.

If is a valid sub pattern but it didn't match anything (e.g. sub pattern 1, matching "b" against "(a)?b") then an empty string is returned.

If the match was obtained using the DFA algorithm, that is using g_regex_match_all() or g_regex_match_all_full(), the retrieved string is not that of a set of parentheses but that of a matched substring. Substrings are matched in reverse order of length, so 0 is the longest match.

The string is fetched from the string passed to the match function, so you cannot call this function after freeing the string.

Returns: The matched substring, or NULL if an error occurred. You have to free the string yourself

Since: 2.14

g_match_info_fetch_pos ( const GMatchInfo *, gint, gint *, gint * )

IMPORT_C gbooleang_match_info_fetch_pos(const GMatchInfo *match_info,
gintmatch_num,
gint *start_pos,
gint *end_pos
)

g_match_info_fetch_pos: : GMatchInfo structure : number of the sub expression : pointer to location where to store the start position : pointer to location where to store the end position

Retrieves the position in bytes of the 'th capturing parentheses. 0 is the full text of the match, 1 is the first paren set, 2 the second, and so on.

If is a valid sub pattern but it didn't match anything (e.g. sub pattern 1, matching "b" against "(a)?b") then and are set to -1 and TRUE is returned.

If the match was obtained using the DFA algorithm, that is using g_regex_match_all() or g_regex_match_all_full(), the retrieved position is not that of a set of parentheses but that of a matched substring. Substrings are matched in reverse order of length, so 0 is the longest match.

Returns: TRUE if the position was fetched, FALSE otherwise. If the position cannot be fetched, and are left unchanged

Since: 2.14

g_match_info_fetch_named ( const GMatchInfo *, const gchar * )

IMPORT_C gchar *g_match_info_fetch_named(const GMatchInfo *match_info,
const gchar *name
)

g_match_info_fetch_named_pos ( const GMatchInfo *, const gchar *, gint *, gint * )

IMPORT_C gbooleang_match_info_fetch_named_pos(const GMatchInfo *match_info,
const gchar *name,
gint *start_pos,
gint *end_pos
)

g_match_info_fetch_all ( const GMatchInfo * )

IMPORT_C gchar **g_match_info_fetch_all(const GMatchInfo *match_info)

g_match_info_fetch_all: : a GMatchInfo structure

Bundles up pointers to each of the matching substrings from a match and stores them in an array of gchar pointers. The first element in the returned array is the match number 0, i.e. the entire matched text.

If a sub pattern didn't match anything (e.g. sub pattern 1, matching "b" against "(a)?b") then an empty string is inserted.

If the last match was obtained using the DFA algorithm, that is using g_regex_match_all() or g_regex_match_all_full(), the retrieved strings are not that matched by sets of parentheses but that of the matched substring. Substrings are matched in reverse order of length, so the first one is the longest match.

The strings are fetched from the string passed to the match function, so you cannot call this function after freeing the string.

Returns: a NULL-terminated array of gchar * pointers. It must be freed using g_strfreev(). If the previous match failed NULL is returned

Since: 2.14