since: 2.14


g_regex_split_simple (
  const gchar* pattern,
  const gchar* string,
  GRegexCompileFlags compile_options,
  GRegexMatchFlags match_options


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 pattern 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 an 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 string 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”.

Available since: 2.14



Type: const gchar*

The regular expression.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.

Type: const gchar*

The string to scan for matches.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.

Type: GRegexCompileFlags

Compile options for the regular expression, or 0


Type: GRegexMatchFlags

Match options, or 0

Return value

Type: An array of utf8

A NULL-terminated array of strings. Free it using g_strfreev()

The array is NULL-terminated.
The caller of the function takes ownership of the data, and is responsible for freeing it.
Each element is a NUL terminated UTF-8 string.