Pattern 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
正则表达式的编译表示形式。
[Android.Runtime.Register("java/util/regex/Pattern", DoNotGenerateAcw=true)]
public sealed class Pattern : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable
[<Android.Runtime.Register("java/util/regex/Pattern", DoNotGenerateAcw=true)>]
type Pattern = class
inherit Object
interface ISerializable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- 继承
- 属性
- 实现
注解
正则表达式的编译表示形式。
指定为字符串的正则表达式必须首先编译为此类的实例。 然后,生成的模式可用于创建一个 Matcher
对象,该对象可以匹配正则表达式的任意 java.lang.CharSequence 字符序列。 执行匹配所涉及的所有状态都驻留在匹配程序中,因此许多匹配程序可以共享相同的模式。
因此,典型的调用序列是
<blockquote>
Pattern p = Pattern.{@link #compile compile}("a*b");
Matcher m = p.{@link #matcher matcher}("aaaaab");
boolean b = m.{@link Matcher#matches matches}();
</blockquote>
#matches matches
此类定义方法是为了方便使用正则表达式一次。 此方法编译表达式,并在单个调用中针对该表达式匹配输入序列。 语句
<blockquote>
boolean b = Pattern.matches("a*b", "aaaaab");
</blockquote>
等效于上述三个语句,但对于重复匹配,效率较低,因为它不允许重用编译的模式。
此类的实例是不可变的,可供多个并发线程安全使用。 类的 Matcher
实例对于此类使用不安全。
<h2>“sum”>正则表达式构造摘要</h2>
<table class=“borderless”><描述文字 style=“display:none”>Regular expression constructs, and what they match</描述文字><thead style=“text-align:left”><tr><th id=“construct”construct</>th<>id=“matchs”>Matchs</th></tr></thead><tbody style=“text-align:left”>
<tr><th colspan=“2” style=“padding-top:20px” id=“characters”>Characters</th></tr>
<tr><th style=“vertical-align:top; font-weight: normal” id=“x”>x</th><td headers=“matches characters x”>The character x</td></tr><><th style=“vertical-align:top; font-weight: normal” id=“backslash”>\\
</th><td headers=“matches characters backslash”>The backslash character</td></tr<>><th style=“vertical-align:top; font-weight: normal” id=“octal_n”>\0
n</th><td headers=“matches characters octal_n”>具有八进制值 0
n (0 的字符 <=
n <=
7) </td></tr<><>th style=“vertical-align:top; font-weight: normal” id=“octal_nn”>\0
nn</th><td headers=“matches characters octal_nn”>the character with octal value0
nn (0 <=
n <=
7) </td></tr<><>th style=“vertical-align:top; font-weight: normal” id=“octal_nnn”\0
>mnn</th<>td headers=“matches characters octal_nnn”>具有八进制值的0
字符 mnn (0 <=
m <=
3, 0 <=
n <=
7) </td></tr><th><style=“vertical-align:top; font-weight: normal” id=“hex_hh”>\x
hh</th><td headers=“matches characters hex_hh”>the character with hexah<0x
/td></tr><><th style=“vertical-align:top; font-weight: normal” id=“hex_hhhh”>\u
hhhh</th><td headers=“matches characters hex_hhhh”>具有十六进制  的字符;value 0x
hhhhh</td></tr><th><style=“vertical-align:top; font-weight: normal” id=“hex_h_h”>\x
{h...h}</th><td headers=“匹配字符hex_h_h”>具有十六进制值的0x
字符 h...h (java.lang.Character#MIN_CODE_POINT Character.MIN_CODE_POINT
<= 0x
H。。。h <= ) /td></tr<>th><style=“vertical-align:top; font-weight: normal” id=“unicode_name”>\N{
name}
</th><td headers=“matches characters unicode_name”>具有 Unicode 字符名称 'name'</td></tr><><th style=“vertical-align:top; font-weight:normal” id=“tab”>\t
</th><td headers=“matches characters tab java.lang.Character#MAX_CODE_POINT Character.MAX_CODE_POINT
<“>制表符 ('\u0009'
) </td></tr><tr><th style=”vertical-align:top; font-weight:normal“ id=”newline“<>\n
/th<>td headers=”matches characters newline“>the newline (换行符) character ('\u000A'
) </td></tr><<>th style=”vertical-align:top; font-weight:normal“ id=”return“<\r
>/th><td headers=”matches characters return”>回车符 ('\u000D'
) /td></tr><><th style=“vertical-align:top; font-weight:normal” id=“form_feed”\f
<>/th><td headers=“matches characters form_feed”>the form-feed character ('\u000C'
) </td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“bell”\a
<>/th><td headers=“matches characters bell”><警报 (铃) 字符 ('\u0007'
) </td></tr<>><th style=“vertical-align:top; font-weight:normal” id=“escape”\e
></th<>td headers=“matches characters escape”>the escape character ('\u001B'
) </td></tr><><th style=“vertical-align:top; font-weight:normal” id=“ctrl_x”>\c
x</th><td headers=“matches characters ctrl_x”>对应于 x</td></tr 的控制字符>
<tr><th colspan=“2” style=“padding-top:20px” id=“classes”>Character classes</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“simple”><[abc]
/th><td headers=“matches classes simple”>a
, b
, 或 c
(simple class) </td></tr><><th style=“vertical-align:top; font-weight:normal” id=“negation”[^abc]
></th><td headers=“matches classes negation”>除 a
之外b
的任何字符, 或 c
(negation) </td></tr tr><><th style=“vertical-align:top;font-weight:normal“ id=”range“>[a-zA-Z]
</th><td headers=”matches classes range“>a
through z
or A
through Z
, inclusive (range) </td></tr<><>th style=”vertical-align:top; font-weight:normal“ id=”union“<[a-d[m-p]]
>/th<>td headers=”matches classes union“>a
through d
, 或 m
through p
: [a-dm-p]
(union) </td></tr tr><><th style=“vertical-align:top;font-weight:normal“ id=”intersection“><[a-z&&[def]]
/th><td headers=”matches classes intersection“>d
, e
或 f
(交集) </tr<><>th style=”vertical-align:top; font-weight:normal“ id=”subtraction1“<[a-z&&[^bc]]
>/th><td headers=”matches classes subtraction1“>a
到 z
,但 和 c
除外b
: [ad-z]
(减法) </td></tr tr><><th style=“vertical-align:top;font-weight:normal“ id=”subtraction2“><[a-z&&[^m-p]]
/th><td headers=”matches classes subtraction2“>a
through z
, not m
through p
: [a-lq-z]
(减) </td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“predef”>Predefined character classes</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“any”><.
/th><td headers=“matchs predef any”>任何字符 (可能与行终止符) </td></tr<>><th style=“vertical-align:top; font-weight:normal” id=“digit”>\d
</th><td headers=“matches predef digit”>A digit: \p{IsDigit
}</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“non_digit”>\D
</th>td headers=“matches predef non_digit”>A non-digit: [^\d]
</td></tr<>tr><th style=“vertical-align:top; font-weight:normal” id=“horiz_white”<>\h
/th><td headers=“matches predef horiz_white”>A 水平空格字符: [ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]
</td></tr<>th><style=“vertical-align:top; font-weight:normal” id=“non_horiz_white”<>\H
/th<>td headers=“matches predef non_<horiz_white“>非水平空格字符: [^\h]
</td></tr<>tr><th style=”vertical-align:top; font-weight:normal“ id=”white“<>\s
/th><td headers=”matches predef white“>A whitespace character: \p{IsWhite_Space
}</td></tr><th><style=”vertical-align:top; font-weight:normal“ id=”non_white“<\S
>/th><td headers=”matches predef non_white“>A non-whitespace character:[^\s]
</td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“vert_white”<\v
>/th<>td headers=“matches predef vert_white”>A 垂直空格字符:<[\n\x0B\f\r\x85\u2028\u2029]
/td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“non_vert_white”>\V
</th<>td headers=“matches predef non_vert_white”>A 非垂直空格字符: [^\v]
</td></Tr><tr><th style=“vertical-align:top; font-weight:normal” id=“word”>\w
</th><td headers=“matches predef word”>A word character: [\p{alpha
\p{gc=Mark}\p{digit}\p{gc=Connector_Punctuation}\p{Join_Control}]}</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“non_word”>\W
</th<>td headers=“matches predef non_word”>A 非单词字符: [^\w]
</td></Tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“posix”><b>POSIX 字符类 (Unicode 感知) </b></th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“Lower”>\p{Lower
}</th><td headers=“matches posix Lower”>A小写字母字符: \p{IsLowercase
}</td></tr><<>th style=“vertical-align:top; font-weight:normal” id=“Upper”>\p{Upper
}</th><td headers=“matches posix Upper”>An大写字母字符:\p{IsUppercase
}</td></tr><th><style=“vertical-align:top; font-weight:normal“ id=”ASCII“>}/th><td headers=”matches posix ASCII“>All ASCII:[\x00-\x7F]
</td></tr><th><style=”vertical-align:top; font-weight:normal“ id=”Alpha“\p{Alpha
>}</th<>td headers=”matches posix Alpha“>An alphabetic character:[\p{IsAlphabetic
]}</td></tr><<>th style=”vertical-align:top; font-weight:normal“ id=”Digit“\p{IsDigit
>}</th><td headers=”matches posix Digit”<\p{ASCII
>十进制数字: \p{gc=Decimal_Number
}</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“Alnum”>\p{Alnum
}</th<>td headers=“matches posix Alnum”>An alphanumeric character:[\p{Alpha
\p{Digit}]}</td></tr<><>th style=“vertical-align:top; font-weight:normal” id=“Punct”>\p{Punct
}</th><td headers=“matches posix Punct”>Punctuation: \p{IsPunctuation
}</td></tr><th><style=“vertical-align:top;font-weight:normal“ id=”Graph“>}/th><td headers=”matches posix Graph“>A 可见字符: [^p{space
\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]}</td></tr<><>th style=”vertical-align:top; font-weight:normal“ id=”Print“\p{Print
>}</th<>td headers=”matches posix Print“>A 可打印字符: [\p{Graph
\p{Blank}&&[^\p{Cntrl}]]}</td></tr>><<<\p{Graph
th style=“vertical-align:top;font-weight:normal“ id=”Blank“>}/th><td headers=”matches posix Blank“>A 空格或制表符: [\p{gc=Space_Separator
\N{CHARACTER TABULATION}]}</td></tr><<>th style=”vertical-align:top; font-weight:normal“ id=”Cntrl“>\p{Cntrl
}</th><td headers=”matches posix Cntrl“>A 控制字符: \p{gc=Control
}</td></tr>><<th style=”vertical-align:top; font-weight:normal“ id=”XDigit<\p{Blank
“>}/th><td headers=”matches posix XDigit“>十六进制数字: [\p{gc=Decimal_Number
\p{IsHex_Digit}]}</td></tr><><th style=”vertical-align:top; font-weight:normal“ id=”Space“\p{Space
>}</th><td headers=”matches posix Space“>A whitespace character: \p{IsWhite_Space
}</td></tr><tr><th style=”vertical-align:top; font-weight:normal“ id=”PosixCompatible”><\p{XDigit
POSIX-Compatible expression</th><td headers=“matches posixCompatible”>See Unicode documentation</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“java”>java.lang.Character 类 (简单 java 字符类型) </th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“javaLowerCase”>\p{javaLowerCase
}</th><td headers=“matches javalowerCase”>等效于 java.lang.Character.isLowerCase () </td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“javaUpperCase”\p{javaUpperCase
>}</th><td headers=“matches java javaUpperCase”>等效于 java.lang.Character.isUpperCase () </td></tr><><th style=“vertical-align:top;font-weight:normal“ id=”javaWhitespace“>}/th><td headers=”matches java javaWhitespace“>等效于 java.lang.Character.isWhitespace () </td></tr<><>th style=”vertical-align:top; font-weight:normal“ id=”javaMirrored“\p{javaMirrored
>}</th><td headers=”matches java javaMirrored“>等效于 java.lang.Character.isMirrored () </td></tr<\p{javaWhitespace
>
<tr><th colspan=“2” style=“padding-top:20px” id=“unicode”>类,用于 Unicode 脚本、块、类别和二进制属性</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“IsLatin”>\p{IsLatin
}</th><td headers=“matches unicode IsLatin”>A Latin script character (script) /td></tr<>th><style=“vertical-align:top; font-weight:normal” id=“InGreek”\p{InGreek
>}</th><td headers=“matches unicode InGreek”>A character inGreek in the Greek <block (block) /td/tr>><<th style=“vertical-align:top; font-weight:normal” id=“Lu”>\p{Lu
}</th><td headers=“matches unicode Lu”>一个大写字母 (类别) </td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“IsAlphabetic”\p{IsAlphabetic
>}</th><td headers=“matches unicode IsAlphabetic”>一个字母字符 (二进制属性) </td></tr><<tr th style=“vertical-align:top; font-weight:normal” id=“Sc”>\p{Sc
}</th><td headers=“matches unicode Sc”>A currency symbol</td></tr><><th style=“vertical-align:top; font-weight:normal” id=“not_InGreek”\P{InGreek
>}</th<>td headers=“matches unicode not_InGreek”>除希腊方块中除一个字符之外的任何字符 () </td></tr tr><><><><th style=“vertical-align:top;font-weight:normal“ id=”not_uppercase“>[\p{L
&&[^\p{Lu}]]}</th><td headers=”matches unicode not_uppercase“>除大写字母之外的任何字母 (减法) </td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“bounds”>Boundary matchers</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“begin_line”<>^
/th><td headers=“matches bounds begin_line”>a line</td></tr<>th><style=“vertical-align:top; font-weight:normal” id=“end_line”>$
</th><td headers=“matches bounds end_line”>the end of a line</td></tr<>><th style=“vertical-align:top; font-weight:normal” id=“word_boundary”>\b
</th><td headers=“matches bounds word_boundary”>A word boundary</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“non_word_boundary”\B
></th<>td headers=“matches bounds non_word_boundary”>A non-word boundary</td></tr><<>th style=“vertical-align:top; font-weight:normal” id=“begin_input”\A
<>/th><td headers=“matches boundsbegin_input“>input/td></tr><><th style=”vertical-align:top; font-weight:normal“ id=”end_prev_match“\G
<>/th><td headers=”matchs bounds end_prev_match“>上一个 match</td></tr>><<th style=”vertical-align:top; font-weight:normal“ id=”end_input_except_term“\Z
<>/th><td headers=”matchs bounds end_input_except_term”><输入的末尾,但对于最终终止符,如果 any</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“end_input”>\z
</th<>td headers=“matches bounds end_input”>the end of the input</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“linebreak”>Linebreak matcher</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“any_unicode_linebreak”\R
<>/th><td headers=“matches linebreak any_unicode_linebreak”>Any Unicode 换行序列“等效于 \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“grapheme”>Unicode Extended Grapheme matcher</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“grapheme_any”>\X
</th<>td headers=“matches grapheme grapheme_any”>Any Unicode extended grapheme cluster</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“greedy”>Greedy 限定符</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“greedy_once_or_not”>X?
</th><td headers=“matches greedy greedy_once_or_not”>X, once or not at at all</td></tr<>tr><th style=“vertical-align:top; font-weight:normal” id=“greedy_zero_or_more”>X*
</th<>td headers=“matches greedy greedy_zero_or_more”>X, zero or more times</td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“greedy_one_or_more”>X+
</th<>td headers=“matches greedy greedy_one_or_more”>X, one or more times</td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“greedy_exactly”>X{
n<}
/th<>td headers=“matches greedy greedy_exactly”>X, exactly n times</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“greedy_at_least”>X{
n,
}</th<>td headers=“matches greedy greedy_at_least”>X, 至少 n times</td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“greedy_at_least_up_to”>X{
n,
m<}
/th><td headers=“matches greedy greedy_at_least_up_to”>X,至少 n 但不超过 m times</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“reluc”>不情愿限定符</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“reluc_once_or_not”>X??
</th<>td headers=“matches reluc reluc_once_or_not”>X, once or not at at all</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“reluc_zero_or_more”>X*?
</th<>td headers=“matches reluc reluc_zero_or_more”>X, zero or more times</td></tr><><th style=“vertical-align:top;font-weight:normal“ id=”reluc_one_or_more“>X+?
</th><td headers=”matches reluc reluc_one_or_more“>X, 一个或多个 times</td></tr<>><th style=”vertical-align:top; font-weight:normal“ id=”reluc_exactly“>X{
n}?
</th><td headers=”matches reluc reluc_exactly“>X, exactly n times</td></tr tr><><th style=“vertical-align:top;font-weight:normal“ id=”reluc_at_least“>X{
n,}?
</th<>td headers=”matches reluc reluc_at_least“>X, 至少 n times</td></tr><th><style=”vertical-align:top; font-weight:normal“ id=”reluc_at_least_up_to“>X{
n,
m}?
</th><td headers=”matches reluc reluc_at_least_up_to“>X, 至少 n但不超过 m times</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“poss”>Possessive 限定符</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“poss_once_or_not”>X?+
</th<>td headers=“matches poss poss_once_or_not”>X, once or not at all</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“poss_zero_or_more”>X*+
</th<>td headers=“matches poss poss_zero_or_more”>X, 零或更多次</td></tr>tr><<th style=“vertical-align:top;font-weight:normal“ id=”poss_one_or_more“>X++
</th><td headers=”matches poss poss_one_or_more“>X, 一次或多次</td></tr<>><th style=”vertical-align:top; font-weight:normal“ id=”poss_exactly“>X{
n}+
</th><td headers=”matches poss poss_exactly“>X, exactly n times</td></tr><><th style=“vertical-align:top;font-weight:normal“ id=”poss_at_least“>X{
n,}+
</th<>td headers=”matches poss poss_at_least“>X, 至少 n times</td></tr<>th><style=”vertical-align:top; font-weight:normal“ id=”poss_at_least_up_to“>X{
n,
m}+
</th><td headers=”matches poss poss_at_least_up_to“>X, 至少 n但不超过 m times</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“logical”>Logical operators</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“concat”>XY</th><td headers=“matches logical concat”>X 后跟 Y</td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“alternate”>X|
Y</th><td headers=“matches logical alternate”>Either X or Y</td></tr><><th style=“vertical-align:top;font-weight:normal“ id=”group“>(
X)
</th><td headers=”matches logical group“>X, as a capturing group</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“backref”>Back references</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“back_nth”\
>n</th><td headers=“matches backref back_nth”>无论 n<sup>th</sup> 捕获组 matched</td></tr><th><style=“vertical-align:top; font-weight:normal” id=“back_named”>\
k<name></th><td headers=“matches backref back_named”>无论匹配的命名捕获组“name”。 仅适用于 API 26 或更高版本</td></tr>
<tr><th colspan=“2” style=“padding-top:20px” id=“quote”>Quote</th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“quote_follow”<\
>/th><td headers=“matches quote quote_follow”Nothing,> but quotes following character</td></tr<>><th style=“vertical-align:top; font-weight:normal” id=“quote_begin”><\Q
/th><td headers=“matches quote quote_begin”>Nothing,但引用所有字符直到 \E
</td></tr tr><><th style=“vertical-align:top;font-weight:normal“ id=”quote_end“>\E
</th<>td headers=”matches quote quote_end“Nothing,> but end quoteed started by \Q
</td></tr><-- Metachars: !$ () *+.?<>[\]^{|}-->
<tr><th colspan=“2” style=“padding-top:20px” id=“special”>特殊构造 (命名捕获和非捕获) </th></tr>
<tr><th style=“vertical-align:top; font-weight:normal” id=“named_group”(?<<a href="#groupname">name</a>>
>X)
</th><td headers=“匹配特殊named_group”>X,作为命名捕获组。 仅适用于 API 26 或更高版本。</td></tr><tr><th style=“vertical-align:top; font-weight:normal” id=“non_capture_group”(?:
>X)
</th><td headers=“matches special non_capture_group”>X,as a non-capturing group</td></tr><><th style=“vertical-align:top; font-weight:normal” id=“flags”>(?idmsux-idmsux)
</th> sU on - off</td></tr><><th style=“vertical-align:top; font-weight:normal” id=“non_capture_group_flags“>(?idmsuxU-idmsuxU:
X)
</th><td headers=“matches special non_capture_group_flags”>X, as 具有给定标志 du</a > U on - off</td></tr><><th style=“vertical-align:top; font-weight:normal” id=“pos_lookahead”><c> (?=</c><i>X</i><c>) </c></th<>td headers=“matches special pos_lookahead”><i>X</i>, via zero-width positive lookahead</td></Tr><tr><th style=“vertical-align:top; font-weight:normal” id=“neg_lookahead”><c> (?!</c><i>X</i><c>) </c></th<>td headers=“matches special neg_lookahead”><i>X</i>, via zero-width negative lookahead</td></tr><<>th style=“vertical-align:top; font-weight:normal” id=“pos_lookbehind”><c> (?<=</c><i>X</i><c>) </c></th><td headers=“matches special pos_lookbehind”><i>X</i>, via零宽度正 lookbehind</td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“neg_lookbehind”><c> (?<!</c><i>X</i><c>) </c></th><td headers=“matches special neg_lookbehind”><i>X</i>, via zero-width negative lookbehind</td></tr>><<th style=“vertical-align:top; font-weight:normal” id=“indep_non_capture_group”><c> (?></c><i>X</i><c>) </c></th><td headers=“matches special indep_non_capture_group”><i>X</i>,作为独立的非捕获组</td></tr>
</tbody></table>
<小时>
<h2>“bs”>反斜杠、转义和引用</h2>
反斜杠字符 ('\'
) 用于引入上表中定义的转义构造,以及引用否则将被解释为未转义构造的字符。 因此,表达式 \\
匹配单个反斜杠,并 \{
匹配左大括号。
在任何不表示转义构造的字母字符之前使用反斜杠是错误的;这些保留用于将来对正则表达式语言的扩展。 反斜杠可以在非字母字符之前使用,而不管该字符是否是未转义构造的一部分。
Java 源代码中字符串文本中的反斜杠通过 <引用>Java 语言规范</引用> 解释为 Unicode 转义 (节 {
在 1.4 中添加。
的 java.util.regex.Pattern
Java 文档。
此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。
字段
CanonEq |
已过时.
Android 不支持此标志。 |
CaseInsensitive |
已过时.
启用不区分大小写的匹配。 |
Comments |
已过时.
允许模式中的空格和注释。 |
Dotall |
已过时.
启用 dotall 模式。 |
Literal |
已过时.
启用模式的文本分析。 |
Multiline |
已过时.
启用多行模式。 |
UnicodeCase |
已过时.
启用 Unicode 感知大小写折叠。 |
UnicodeCharacterClass |
已过时.
Android 不支持此标志,并且始终使用 Unicode 字符类。 |
UnixLines |
已过时.
启用 Unix 行模式。 |
属性
Class |
返回此 |
Handle |
基础 Android 实例的句柄。 (继承自 Object) |
JniIdentityHashCode |
正则表达式的编译表示形式。 (继承自 Object) |
JniPeerMembers |
正则表达式的编译表示形式。 |
PeerReference |
正则表达式的编译表示形式。 (继承自 Object) |
ThresholdClass |
此 API 支持 Mono for Android 基础结构,不应直接从代码中使用。 (继承自 Object) |
ThresholdType |
此 API 支持 Mono for Android 基础结构,不应直接从代码中使用。 (继承自 Object) |
方法
AsMatchPredicate() |
创建一个谓词,用于测试此模式是否与给定的输入字符串匹配。 |
AsPredicate() |
创建一个谓词,用于测试是否在给定的输入字符串中找到此模式。 |
Clone() |
创建并返回此对象的副本。 (继承自 Object) |
Compile(String) |
将给定的正则表达式编译为模式。 |
Compile(String, RegexOptions) |
将给定的正则表达式编译为具有给定标志的模式。 |
Dispose() |
正则表达式的编译表示形式。 (继承自 Object) |
Dispose(Boolean) |
正则表达式的编译表示形式。 (继承自 Object) |
Equals(Object) |
指示某个其他对象是否“等于”此对象。 (继承自 Object) |
Flags() |
返回此模式的匹配标志。 |
GetHashCode() |
返回对象的哈希代码值。 (继承自 Object) |
InvokePattern() |
返回从中编译此模式的正则表达式。 |
JavaFinalize() |
当垃圾回收确定不再引用对象时,由垃圾回收器对对象调用。 (继承自 Object) |
Matcher(ICharSequence) |
创建一个匹配程序,该匹配程序将针对此模式匹配给定的输入。 |
Matcher(String) |
创建一个匹配程序,该匹配程序将针对此模式匹配给定的输入。 |
Matches(String, ICharSequence) |
编译给定的正则表达式,并尝试将给定的输入与其匹配。 |
Matches(String, String) |
编译给定的正则表达式,并尝试将给定的输入与其匹配。 |
Notify() |
唤醒正在等待此对象的监视器的单个线程。 (继承自 Object) |
NotifyAll() |
唤醒正在等待此对象的监视器的所有线程。 (继承自 Object) |
Quote(String) |
返回指定 |
SetHandle(IntPtr, JniHandleOwnership) |
设置 Handle 属性。 (继承自 Object) |
Split(ICharSequence) |
围绕此模式的匹配项拆分给定的输入序列。 |
Split(ICharSequence, Int32) |
围绕此模式的匹配项拆分给定的输入序列。 |
Split(String) |
围绕此模式的匹配项拆分给定的输入序列。 |
Split(String, Int32) |
围绕此模式的匹配项拆分给定的输入序列。 |
ToArray<T>() |
正则表达式的编译表示形式。 (继承自 Object) |
ToString() |
返回对象的字符串表示形式。 (继承自 Object) |
UnregisterFromRuntime() |
正则表达式的编译表示形式。 (继承自 Object) |
Wait() |
导致当前线程等待,直到它被唤醒,通常是通过 em <通知/em> 或 <em>interrupted</em>。<> (继承自 Object) |
Wait(Int64) |
导致当前线程等待,直到它被唤醒,通常是通过 em <通知/em> 或 <em>interrupted</em>,或直到经过一定数量的实时。<> (继承自 Object) |
Wait(Int64, Int32) |
导致当前线程等待,直到它被唤醒,通常是通过 em <通知/em> 或 <em>interrupted</em>,或直到经过一定数量的实时。<> (继承自 Object) |
显式接口实现
IJavaPeerable.Disposed() |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.DisposeUnlessReferenced() |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.Finalized() |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.JniManagedPeerState |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
正则表达式的编译表示形式。 (继承自 Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) |
正则表达式的编译表示形式。 (继承自 Object) |
扩展方法
JavaCast<TResult>(IJavaObject) |
执行 Android 运行时检查的类型转换。 |
JavaCast<TResult>(IJavaObject) |
正则表达式的编译表示形式。 |
GetJniTypeName(IJavaPeerable) |
正则表达式的编译表示形式。 |