📄 glib-perl-compatible-regular-expressions.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Perl-compatible regular expressions</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="next" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Glob-style-pattern-matching.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Simple-XML-Subset-Parser.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3142793" class="shortcut">Top</a>  |  <a href="#id3144206" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-Perl-compatible-regular-expressions"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3142793"></a><span class="refentrytitle">Perl-compatible regular expressions</span></h2><p>Perl-compatible regular expressions — matches strings against regular expressions</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h>enum <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexError">GRegexError</a>;#define <a class="link" href="glib-Perl-compatible-regular-expressions.html#G-REGEX-ERROR:CAPS">G_REGEX_ERROR</a>enum <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexCompileFlags">GRegexCompileFlags</a>;enum <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a>; <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a>;<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> (<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexEvalCallback">*GRegexEvalCallback</a>) (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, <a class="link" href="glib-Strings.html#GString">GString</a> *result, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-new">g_regex_new</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *pattern, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexCompileFlags">GRegexCompileFlags</a> compile_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-ref">g_regex_ref</a> (<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex);void <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-unref">g_regex_unref</a> (<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-get-pattern">g_regex_get_pattern</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-get-max-backref">g_regex_get_max_backref</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-get-capture-count">g_regex_get_capture_count</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-get-string-number">g_regex_get_string_number</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *name);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-escape-string">g_regex_escape_string</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gint">gint</a> length);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-match-simple">g_regex_match_simple</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *pattern, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexCompileFlags">GRegexCompileFlags</a> compile_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-match">g_regex_match</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> **match_info);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-match-full">g_regex_match_full</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> **match_info, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-match-all">g_regex_match_all</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> **match_info);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-match-all-full">g_regex_match_all_full</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> **match_info, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>** <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-split-simple">g_regex_split_simple</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *pattern, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexCompileFlags">GRegexCompileFlags</a> compile_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>** <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-split">g_regex_split</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>** <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-split-full">g_regex_split_full</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Basic-Types.html#gint">gint</a> max_tokens, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-replace">g_regex_replace</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *replacement, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-replace-literal">g_regex_replace_literal</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *replacement, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-replace-eval">g_regex_replace_eval</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a> *regex, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> string_len, <a class="link" href="glib-Basic-Types.html#gint">gint</a> start_position, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags">GRegexMatchFlags</a> match_options, <a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexEvalCallback">GRegexEvalCallback</a> eval, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-check-replacement">g_regex_check_replacement</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *replacement, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> *has_references, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error); <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a>;<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegex">GRegex</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-get-regex">g_match_info_get_regex</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-get-string">g_match_info_get_string</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);void <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-free">g_match_info_free</a> (<a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-matches">g_match_info_matches</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-next">g_match_info_next</a> (<a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-get-match-count">g_match_info_get_match_count</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-is-partial-match">g_match_info_is_partial_match</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-expand-references">g_match_info_expand_references</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string_to_expand, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-fetch">g_match_info_fetch</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, <a class="link" href="glib-Basic-Types.html#gint">gint</a> match_num);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-fetch-pos">g_match_info_fetch_pos</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, <a class="link" href="glib-Basic-Types.html#gint">gint</a> match_num, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *start_pos, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *end_pos);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-fetch-named">g_match_info_fetch_named</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *name);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-fetch-named-pos">g_match_info_fetch_named_pos</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *name, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *start_pos, <a class="link" href="glib-Basic-Types.html#gint">gint</a> *end_pos);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>** <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-fetch-all">g_match_info_fetch_all</a> (const <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo">GMatchInfo</a> *match_info);</pre></div><div class="refsect1" lang="en"><a name="id3144206"></a><h2>Description</h2><p>The <code class="function">g_regex_*()</code> functions implement regularexpression pattern matching using syntax and semantics similar toPerl regular expression.</p><p>Some functions accept a <em class="parameter"><code>start_position</code></em> argument,setting it differs from just passing over a shortened string and setting<a class="link" href="glib-Perl-compatible-regular-expressions.html#G-REGEX-MATCH-NOTBOL:CAPS"><span class="type">G_REGEX_MATCH_NOTBOL</span></a> in the case of a pattern that begins with any kindof lookbehind assertion.For example, consider the pattern "\Biss\B" which finds occurrences of "iss"in the middle of words. ("\B" matches only if the current position in thesubject is not a word boundary.) When applied to the string "Mississipi"from the fourth byte, namely "issipi", it does not match, because "\B" isalways false at the start of the subject, which is deemed to be a wordboundary. However, if the entire string is passed , but with<em class="parameter"><code>start_position</code></em> set to 4, it finds the secondoccurrence of "iss" because it is able to look behind the starting pointto discover that it is preceded by a letter.</p><p>Note that, unless you set the <a class="link" href="glib-Perl-compatible-regular-expressions.html#G-REGEX-RAW:CAPS"><span class="type">G_REGEX_RAW</span></a> flag, all the strings passedto these functions must be encoded in UTF-8. The lengths and the positionsinside the strings are in bytes and not in characters, so, for instance,"\xc3\xa0" (i.e. "à") is two bytes long but it is treated as a singlecharacter. If you set <a class="link" href="glib-Perl-compatible-regular-expressions.html#G-REGEX-RAW:CAPS"><span class="type">G_REGEX_RAW</span></a> the strings can be non-valid UTF-8strings and a byte is treated as a character, so "\xc3\xa0" is two bytesand two characters long.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -