Regex
Object Hierarchy:
Description:
A GRegex is the "compiled" form of a regular expression pattern.
This structure is opaque and its fields cannot be accessed directly.
Namespace: GLib
Package: glib-2.0
Content:
Static methods:
-
public static string escape_string (string str, int length = -1)
Escapes the special characters used for regular expressions in string, for instance "a.b*c" becomes
"a\.b\*c".
-
public static bool match_simple (string pattern, string str, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0)
Scans for a match in string for pattern.
-
public static string[] split_simple (string pattern, string str, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0)
Breaks the string on the pattern, and returns an array of the tokens.
-
public static bool check_replacement (out bool has_references = null) throws RegexError
Checks whether replacement is a valid replacement string (see g_regex_replace()), i.e. that all escape
sequences in it are valid.
Creation methods:
Methods:
-
public unowned string get_pattern ()
Gets the pattern string associated with regex, i.e. a copy of the string passed to g_regex_new().
-
public RegexCompileFlags get_compile_flags ()
Returns the compile options that regex was created with.
-
public RegexMatchFlags get_match_flags ()
Returns the match options that regex was created with.
-
public int get_max_backref ()
Returns the number of the highest back reference in the pattern, or 0 if the pattern does not contain
back references.
-
public int get_capture_count ()
Returns the number of capturing subpatterns in the pattern.
-
public int get_string_number (string name)
Retrieves the number of the subexpression named name.
-
public bool match (string str, RegexMatchFlags match_options = 0, out MatchInfo match_info = null)
Scans for a match in string for the pattern in regex.
-
public bool match_full (string str, ssize_t string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError
Scans for a match in string for the pattern in regex.
-
public bool match_all (string str, RegexMatchFlags match_options = 0, out MatchInfo match_info = null)
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().
-
public bool match_all_full (string str, ssize_t string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError
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 "<a> <b> <c>" against the
pattern "<.*>" you get "<a> <b> <c>".
-
public string[] split (string str, RegexMatchFlags match_options = 0)
Breaks the string on the pattern, and returns an array of the tokens.
-
public string[] split_full (string str, ssize_t string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, int max_tokens = 0) throws RegexError
Breaks the string on the pattern, and returns an array of the tokens.
-
public string replace (string str, ssize_t string_len, int start_position, string replacement, RegexMatchFlags match_options = 0) throws RegexError
Replaces all occurrences of the pattern in regex with the replacement text. Backreferences of the form
'\number' or '\g<number>' in the replacement text are interpolated by the number-th captured subexpression of the match, '\g<
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:
-
public string replace_literal (string str, ssize_t string_len, int start_position, string replacement, RegexMatchFlags match_options = 0) throws RegexError
Replaces all occurrences of the pattern in regex with the replacement text.
-
public string replace_eval (string str, ssize_t string_len, int start_position, RegexMatchFlags match_options = 0, RegexEvalCallback eval) throws RegexError
Replaces occurrences of the pattern in regex with the output of eval for that occurrence.