語言

Pattern 類別

定義

一個正則表達式的編譯表示。

[Android.Runtime.Register("java/util/regex/Pattern", DoNotGenerateAcw=true)]
public sealed class Pattern : Java.Lang.Object, IDisposable, 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 字元序列與正則表達式匹配。 所有參與配對的狀態都集中在配對者身上,因此許多配對者可能共享相同的模式。

典型的召喚序列如下

<引用>

Pattern p = Pattern.{@link #compile compile}("a*b");
            Matcher m = p.{@link #matcher matcher}("aaaaab");
            boolean b = m.{@link Matcher#matches matches}();

</區塊引用>

此類別定義的方法 #matches matches ,作為當正則表達式只使用一次時的便利。 此方法編譯一個表達式,並在單一調用中將輸入序列與之匹配。 陳述式

<引用>

boolean b = Pattern.matches("a*b", "aaaaab");

</區塊引用>

等價於上述三個陳述,但對於重複匹配,效率較低,因為它不允許重複使用已編譯的模式。

此類別的實例是不可變的,且可被多個並行執行緒安全使用。 該類別的實例 Matcher 並不安全用於此類用途。

<h2>“sum”> 正則表達式構造<摘要/h2>

<table class=“borderless”caption style=“display:none”>正則表達式結構及其匹配</caption><thead style=“text-align:left”><tr><th id=“construct”>Construct</th><th id=“matches”> Matches</th></tr></thead><tbody style=“text-align:left”><>

<TR><th colspan=“2” style=“padding-top:20px” id=“characters”> Characters</th></tr>

TRth style=“vertical-align:top;font-weight: normal” id=“x”x/thtd headers=“matched characters x” 字元 x/td/trtr thstyle =“vertical-align:top; font-weight: normal” id=“backslash”/thtd headers=“match characters backslash” 反斜線 字元/td/trtrth style = “vertical-align:top;font-weight: normal” id=“octal_n”n/thtd 標頭=“匹配字元 octal_n” 八進位值為 n (0&nbsp;&nbsp;n&nbsp;&nbsp;7)/td/trtr th thstyle = “vertical-align:top; font-weight: normal” id=“octal_nn”nn/thtd headers=“match characters octal_nn” 八進位值nn (0&nbsp;&nbsp;n&nbsp;&nbsp;7)/td/trtr thstyle = “vertical-align:top; font-weight: normal” id=“octal_nnn”mnn/thtd headers=“matching characters octal_nnn” 八進位值mnn (0&nbsp;&nbsp;m&nbsp;&nbsp;3, 0&nbsp;&nbsp;n&nbsp;&nbsp;7)/td/trtr thstyle = “vertical-align:top; font-weight: normal” id=“hex_hh”hh/thtd headers=“matching characters hex_hh” 帶有十六進位值的字元 hh/td/trtr thstyle = “vertical-align:top; font-weight: normal” id=“hex_hhhh”hhhh/thtd headers=“matching characters hex_hhhh” 字元十六進制&nbsp;價值&nbsp;哈哈/td/trTR THstyle=“vertical-align:top;font-weight: normal” id=“hex_h_h”{h...h}/thtd 標頭=“匹配字元 hex_h_h” 具有十六進位值 h... 的字元H&nbsp;<=&nbsp;呃......h&nbsp;<=&nbsp;/td/trtr thstyle = “vertical-align:top; font-weight: normal” id=“”unicode_name“name/thtd headers=”matches characters unicode_name“ 帶有 Unicode 字元名稱 'name'/td/trtr thstyle =”vertical-align:top; font-weight:normal“ id=”tab“/thtd headers=”matches characters tab“ The tabcharacter ()/td/trtr th style= “vertical-align:top; font-weight:normal” id=“newline”/thtd headers=“matched characters newline” 換行(換行)字元 (/td/trtr thstyle = “vertical-align:top; font-weight:normal” id=“return”/thtd headers=“matches characters return” 回車字元 (/td/trtr thstyle = “vertical-align:top; font-weight:normal” id=“form_feed” /thtd headers=“matches characters form_feed” 表單-feed字元 (/td/trtr thstyle=“vertical-align:top; font-weight:normal” id=“bell”/thtd headers=“matches characters bell” alert (bell) 字元 (/td/trTR th style=“vertical-align:top; font-weight:normal” id=“escape”/thtd headers=“matches characters escape” 逃脫字元 (/td/trtr thstyle = “vertical-align:top; font-weight:normal” id=“ctrl_x”x/thtd headers=“matches characters ctrl_x” x/td/tr 的控制字元

<TR><th colspan=“2” style=“padding-top:20px” id=“classes”> 角色類別</th></tr>

<TR><TH style=“vertical-align:top; font-weight:normal” id=“simple”>[abc]</th><td headers=“matches classes simple”>abc , (simple class)</td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“negation”>[^abc]</th><td headers=“match classes negation”> 除了 , , a, /bctd</tr><>tr< 以外的任何字元><TH style=“Vertical-Align:top;font-weight:normal“ id=”range“>[a-zA-Z]</th><TD 標頭=”匹配類別“>a 透過 zAZ包含 (range)</td></tr><tr th><style=”vertical-align:top;font-weight:normal“ id=”union“>[a-d[m-p]]</th><TD 標頭=”匹配類別 Union“>a 透過 d,或m通過 p[a-dm-p] (union)</td></tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”intersection“>[a-z&&[def]]</th><TD 標頭=”匹配類別交叉點“>def (intersection)</tr><tr th><style=”vertical-align:top; font-weight:normal“ id=”subtraction1“>[a-z&&[^bc]]</th><TD 標頭=”匹配類別 subtraction1“>az,但除外 bc 和 : [ad-z] (減法)</td></tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”subtraction2“>[a-z&&[^m-p]]</th><TD 標頭=”匹配類別 subtraction2“>a 透過 z,而非 mp[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=“match predef any”>任意字元(可能與行終結符匹配也可能不匹配)</td></tr><tr th><style=“vertical-align:top;font-weight:normal” id=“digit”>\d</th><td headers=“match predef digit”A> 數字: \p{IsDigit}</td></tr><tr th><style =“vertical-align:top;font-weight:normal” id=“non_digit”>/th\D<td headers=“matches predef non_digit”> 非數字:<> /td[^\d]/tr<><tr th>style=“vertical-align:top; font-weight:normal” id=“horiz_white”<><>/th\h<td headers=“matches predef horiz_white”> 水平空白字元:<>/td[ \t\xA0&#92;u1680&#92;u180e&#92;u2000-&#92;u200a&#92;u202f&#92;u205f&#92;u3000]/tr<><tr th>style=“vertical-align:top; font-weight:normal” id=“non_horiz_white”<><>/th\H<td headers=”><匹配 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“> 空白字元: \p{IsWhite_Space}</td></tr><tr><th style=”vertical-align:top; font-weight:normal“ id=”non_white“>\S</th><td headers=”match predef non_white“A>非空白字元:[^\s]/td</tr><>tr th<style = “vertical-align:top; font-weight:normal” id=“”vert_white“><>\v/th<>td headers=”matches predef vert_white“< 垂直空白字元:>[\n\x0B\f\r\x85&#92;u2028&#92;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“< 非垂直空白>character: [^\v]/td</tr><>tr th th<style=“vertical-align:top; font-weight:normal” id=“word”><>\w/th<>td headers=“matches predef word”<A word character: >\p{gc=Mark}\p{digit}\p{gc=Connector_Punctuation}\p{Join_Control}]}[\p{alpha/td</tr><>tr th<style=“vertical-align:top; font-weight:normal” id=“non_word”><>\W/th<>td headers=“matchs predef non_<「>非詞語字元:[^\w]</td></tr」>

<TR><th colspan=“2” style=“padding-top:20px” id=“posix”><b>POSIX 字元類別 (Unicode aware )</b></th></tr>

<tr><th style=“vertical-align:top; font-weight:normal” id=“Lower”>\p{Lower}</th><td headers=“matches posix Lower”>小寫字母: \p{IsLowercase}</td></tr><tr><th style = “vertical-align:top; font-weight:normal” id=“Upper”>\p{Upper}</th><td headers=“matches posix Upper”> 大寫字母:\p{IsUppercase}</td></tr><tr th><style =“vertical-align:top;font-weight:normal“ id=”ASCII“>}/th\p{ASCII<td headers=”matches posix ASCII“> 所有 ASCII:<>/td[\x00-\x7F]/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”Alpha“<><}>/th\p{Alpha<td headers=”match posix Alpha“>字母:<]}>/td[\p{IsAlphabetic/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”Digit“<><}>/th\p{IsDigit<td headers=”matches posix Digit”><>一個小數位數字:\p{gc=Decimal_Number}</td></tr><tr th><style =“vertical-align:top; font-weight:normal” id=“Alnum”>\p{Alnum}</th><td headers=“match posix Alnum”> 字母數字字元:[\p{Alpha\p{Digit}]}</td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“Punct”>\p{Punct}</th><td headers=“matches posix Punct”> 標點符號: \p{IsPunctuation}</td></tr><tr th><style=“vertical-align:top;font-weight:normal“ id=”Graph“>}/th\p{Graph<td headers=”matches posix Graph“>A visible character: <\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]}>/td[^p{space/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”Print“<><}>/th\p{Print<td headers=”matches posix Print“>可列印字元: <\p{Blank}&&[^\p{Cntrl}]]}>/td[\p{Graph/tr tr<><><><TH style=“Vertical-Align:top;font-weight:normal“ id=”Blank“>}/th\p{Blank<td headers=”matches posix Blank“空白”>空格或制表表: \N{CHARACTER TABULATION}]<}> /TD[\p{gc=Space_Separator/TR<><TR TH>STYLE=“VERTICAL-ALIGN:TOP; FONT-WEIGHT:NORMAL” ID=“Cntrl”<><}>/th\p{Cntrl<td headers=“matches posix Cntrl”>控制字元: <}>/td\p{gc=Control/tr<><tr th>style=“vertical-align:top; font-weight:normal” id=“XDigit<><“>}/th\p{XDigit<td headers=”match posix XDigit“>一個十六進位數字:<\p{IsHex_Digit}]}>/td[\p{gc=Decimal_Number/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”Space“<><}>/th\p{Space<td headers=”matches posix Space“> 一個空白字元: <}>/td\p{IsWhite_Space/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”PosixCompatible“POSIX-Compatible<><>expression</th><td headers=“matches posix PosixCompatible”>請參見 Unicode 文件/<td></tr>

<TR><th colspan=“2” style=“padding-top:20px” id=“java”java.lang.Character> classes (simple java character type)</th></tr>

<tr><th style=“vertical-align:top; font-weight:normal” id=“javaLowerCase”>\p{javaLowerCase}</th><td headers=“matches java 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 tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”javaWhitespace“>}/th\p{javaWhitespace<td headers=”matches java javaWhitespace“>等同於 java.lang.Character.isWhitespace()</td>/tr<><tr>th style=”vertical-align:top; font-weight:normal“ id=”javaMirrored“<><}>/th\p{javaMirrored<td headers=”matches java javaMirrored“> 等同於 java.lang.Character.isMirrored()</td>/tr<><>

<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><>tr th<style = “vertical-align:top; font-weight:normal” id=“InGreek”><>}\p{InGreek/th<>td headers=“matches unicode InGreek”< 希臘語中的一個字元 >block (block)</td></tr><tr th><style = “vertical-align:top; font-weight:normal” id=“Lu”>\p{Lu}</th><td headers=“match unicode Lu”> 大寫字母(category)/<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“>}/th\p{Sc<td headers=”matches unicode Sc“>貨幣符號</td>/tr<><tr th>style=”vertical-align:top; font-weight:normal“ id=”not_InGreek“<><}>/th\P{InGreek<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=“匹配 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=“matchs bounds begin_line”>行首</td></tr><tr th><style = “vertical-align:top; font-weight:normal” id=“end_line”>$</th><td headers=“match bounds end_line”> 行尾</td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“word_boundary”>/th\b<td headers=“match bounds word_boundary”>A word boundary</td>/tr<><tr th>style=“vertical-align:top; font-weight:normal” id=“non_word_boundary”<><>/th\B<td headers=“match bounds non_word_boundary”> 非字邊界</td>/tr<><tr th>style=“vertical-align:top; font-weight:normal” id=“begin_input”<><>/th\A<td headers=“match bounds ><begin_input“>輸入/td</tr><>tr th<style = ”vertical-align:top; font-weight:normal“ id=”end_prev_match“/><>\Gth<>td headers=”match bounds end_prev_match“< 前一個 match>/td</tr><>tr th<style=”vertical-align:top; font-weight:normal“ id=”end_input_except_term“/><>\Zth<>td headers=”match bounds end_input_except_term”<>輸入的末端,除了最後一個終端子,if any</td></tr><tr th><style = “vertical-align:top; font-weight:normal” id=“end_input”/>\z<th><td headers=“match bounds end_input”> 輸入<的結尾 /td></tr>

<tr><th colspan=“2” style=“padding-top:20px” id=“linebreak”> 換行匹配器</th></tr>

<TR><th style=“vertical-align:top;font-weight:normal” id=“any_unicode_linebreak”/>\R<th><td headers=“matches linebreak any_unicode_linebreak”> 任何 Unicode 換行序列,都等同於 &#92;u000D&#92;u000A|[&#92;u000A&#92;u000B&#92;u000C&#92;u000D&#92;u0085&#92;u2028&#92;u2029] </td></tr>

<tr><th colspan=“2” style=“padding-top:20px” id=“grapheme”Unicode> 擴展字素匹配器</th></tr>

<TR><th style=“vertical-align:top; font-weight:normal” id=“grapheme_any”/>\X<th><td headers=“matches grapheme grapheme_any”> 任何 Unicode 擴展字素叢集</td></tr>

<tr><th colspan=“2” style=“padding-top:20px” id=“greedy”> Greedy quantifiers/<th></tr>

<tr><th style=“vertical-align:top; font-weight:normal” id=“greedy_once_or_not”>?</th><td headers=“match greedy greedy_once_or_not”>X, once or no at</td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“greedy_zero_or_more”>X*</th><td headers=“匹配貪婪greedy_zero_or_more”>X,零次或以上</td></tr><TR><th style=“vertical-align:top; font-weight:normal” id=“greedy_one_or_more”>+</th><td headers=“match greedy greedy_one_or_more”>X,一次或多次</td></tr><tr th><style = “vertical-align:top; font-weight:normal” id=“greedy_exactly”>X{n}</th><td headers=“match greedy greedy_exactly”>X,恰好 n 次</td></tr><tr th><style = “vertical-align:top; font-weight:normal” id=“greedy_at_least”>{n,}</th><td headers=“match greedy greedy_at_least”>X,至少 n 次</td></tr><tr><th style = “vertical-align:top; font-weight:normal” id=“greedy_at_least_up_to”>X{n m,}</th><td headers=“匹配貪婪的 greedy_at_least_up_to”>X,至少 n 次,但不超過 m 倍/<TD></TR>

<tr><th colspan=“2” style=“padding-top:20px” id=“reluc”> Reluctant quantifiers/<th></tr>

<tr><th style=“vertical-align:top; font-weight:normal” id=“”reluc_once_or_not“>??</th><td headers=”match reluc reluc_once_or_not“>X, once or never at/td<></tr><tr th><style=”vertical-align:top; font-weight:normal“ id=”reluc_zero_or_more“>X*?</th><td headers=”match reluc reluc_zero_or_more“>X,零次或以上</td></tr><tr><TH style=“Vertical-Align:top;font-weight:normal“ id=”reluc_one_or_more“>+?</th><td headers=”match reluc reluc_one_or_more“>X,一次或多次</td></tr><tr th><style=”vertical-align:top; font-weight:normal“ id=”reluc_exactly“>{ n}?</th><td headers=”matches reluc reluc_exactly“>X,恰好 n 次</td></tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”reluc_at_least“>{n,}?</th><td headers=”match reluc reluc_at_least“>X,至少 n 次</td></tr><tr><th style=”vertical-align:top; font-weight:normal“ id=”reluc_at_least_up_to“>{n,m}?</th><td headers=”match reluc reluc_at_least_up_to“>X,至少 n但不超過M倍</TD/><TR>

<tr><th colspan=“2” style=“padding-top:20px” id=“poss”> 所有格量詞/<th></tr>

<tr><th style=“vertical-align:top; font-weight:normal” id=“poss_once_or_not”>?+</th><td headers=“match poss poss_once_or_not”>X, once or never< at all/td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“poss_zero_or_more”>X*+</th><td headers=“match poss poss_zero_or_more”>X, 0 次或多次</td></tr><tr><TH style=“Vertical-Align:top;font-weight:normal“ id=”poss_one_or_more“>++</th><td headers=”match poss poss_one_or_more“>X, one or more< times / td></tr><tr><th style=”vertical-align:top; font-weight:normal“ id=”poss_exactly“>{ n}+</th><td headers=”match poss poss_exactly“>X, exactly n times</><td/tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”poss_at_least“>{n,}+</th><td headers=”matches poss poss_at_least“>X,至少 n 次</td></tr><tr th><style =”vertical-align:top; font-weight:normal“ id=”poss_at_least_up_to“>{n m,}+</th><td headers=”match poss poss poss_at_least_up_to“>X,至少 n但不超過M倍</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”></th><td headers=“matches logical concat”>X 後接 Y</td></tr><tr th><style=“vertical-align:top; font-weight:normal” id=“alternate”>X|Y</th><td headers=“matches logical alternate”>X 或Y</td></tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”group“>()</th><td headers=”matching logical group“>X,作為擷取群組</td></tr>

<tr><th colspan=“2” style=“padding-top:20px” id=“backref”> Back references</th></tr>

TRth style=“vertical-align:top; font-weight:normal” id=“back_nth”n/thtd headers=“matches backref back_nth”Whatever nsupth/sup captureing group matched/td/trtr thstyle =“vertical-align:top; font-weight:normal” id=“back_named”k<名稱>/thtd headers=“matches backref back_named”,無論名稱捕捉群組「name」匹配什麼。 僅限於 API 26 或以上</TD></tr 等級>

<tr><th colspan=“2” style=“padding-top:20px” id=“quote”> 引用/<th></tr>

<TR><TH style=“vertical-align:top; font-weight:normal” id=“quote_follow”/>\<th><td headers=“match quote quote_follow”>“無,但引用以下字元</td></tr><tr th><style=”vertical-align:top;font-weight:normal“ id=”quote_begin“>\Q</th><td headers=”match quote quote_begin“> 無,但引號所有字元直到 \E</td></tr tr><><TH style=“Vertical-Align:top;font-weight:normal“ id=”quote_end“>\E</th><td headers=”matches quote quote_end“>無,但結束引用由 \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”>(?&lt;<a href="#groupname">name</a>&gt;)</th><td headers=“match special named_group”>X,作為命名捕捉群組。 僅支援 API 26 或以上版本。/td/trtr thstyle = “vertical-align:top; font-weight:normal” id=“non_capture_group”X/thtd headers=“match special non_capture_group”X,作為非擷取群組/td/trtr thstyle=“vertical-align:top; font-weight:normal” id=“flags”/th sU on - off/td/trtr thstyle=“vertical-align:top; font-weight:normal” id=“non_capture_group_flags“X&nbsp;&nbsp;/thtd headers=“match special non_capture_group_flags”X,作為非捕捉群組,旗標為 du/a U on - off/td/trtr thstyle=“vertical-align:top; font-weight:normal” id=“pos_lookahead”c(?=/ciX/ic/c/thtd headers=“match special pos_lookahead”iX/i,透過零寬度正前瞻/td/TRTRTH style=“vertical-align:top; font-weight:normal” id=“neg_lookahead”c(?!/c i X/ic/c/thTD 標頭=“匹配特殊 neg_lookahead”iX/i,透過零寬度負前瞻/td/trtr thstyle =“vertical-align:top; font-weight:normal” id=“pos_lookbehind”c(?<=/ciX/ic)/c/thTD headers=“匹配特殊 pos_lookbehind”iX/i,透過零寬度正面 lookbehind/td/trtr thstyle = “vertical-align:top; font-weight:normal” id=“neg_lookbehind”c(?<!/c i X/ic/c/thTD headers=“匹配特殊 neg_lookbehind”i X/i,透過零寬度負面lookbehind/td/trtr thstyle=“vertical-align:top; font-weight:normal” id=“indep_non_capture_group”c(?>/c i X/ic/c/thtd 標頭=「匹配特殊 indep_non_capture_group」iX/i,作為獨立且非擷取的群組/td/tr

</tbody></表格>

<人資>

<H2>“BS”>反斜線、逃離與引用</h2>

反斜線字元('\')用來介紹逃逸的結構,如上表所定義,並引用原本會被解釋為未逃逸結構的字元。 因此,該表達 \\ 式與單反斜線相符,並 \{ 對應左括號。

在任何不代表逃逸結構的字母前使用反斜線是錯誤;這些資料保留給未來正則表達式語言的擴充。 無論該字元是否屬於未脫離構造,都可以在非字母字元前使用反斜線。

Java 原始碼中字串字面中的反斜線會依 <cite>的 The Java 語言規範</cite> 解釋為 Unicode 逃逸(section {

在 1.4 版本加入。

Java 文件 java.util.regex.Pattern

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

欄位

名稱 Description
CanonEq
已淘汰.

此旗標在 Android 上不支援。

CaseInsensitive
已淘汰.

啟用不區分大小寫的比對。

Comments
已淘汰.

允許在圖案中留白和註解。

Dotall
已淘汰.

啟用 dotall 模式。

Literal
已淘汰.

啟用模式的常值剖析。

Multiline
已淘汰.

啟用多行模式。

UnicodeCase
已淘汰.

啟用 Unicode 感知大小寫折疊。

UnicodeCharacterClass
已淘汰.

此旗標在 Android 上不支援,且始終使用 Unicode 字元類別。

UnixLines
已淘汰.

啟用 Unix 行模式。

屬性

名稱 Description
Class

回傳此 Object的執行時類別。

(繼承來源 Object)
Handle

底層 Android 實例的帳號。

(繼承來源 Object)
JniIdentityHashCode

取得由互通執行時指派給此 Java 對等端的身份雜湊碼。

(繼承來源 Object)
JniManagedPeerState

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
JniPeerMembers

一個正則表達式的編譯表示。

PeerReference

取得這個 Java 節點的 JNI 物件參考。

(繼承來源 Object)
ThresholdClass

此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。

(繼承來源 Object)
ThresholdType

此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。

(繼承來源 Object)

方法

名稱 Description
AsMatchPredicate()

建立一個謂詞來測試此模式是否與給定輸入字串相符。

AsPredicate()

建立一個謂詞,測試該模式是否存在於給定輸入字串中。

Clone()

建立並回傳此物件的副本。

(繼承來源 Object)
Compile(String, RegexOptions)

將給定的正則表達式編譯成帶有指定標誌的模式。

Compile(String)

將給定的正則表達式編譯成一個模式。

Construct(JniObjectReference, JniObjectReferenceOptions)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
Dispose()

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
Dispose(Boolean)

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
DisposeUnlessReferenced()

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
Equals(Object)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
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)

回傳指定 String的字面模式String

SetHandle(IntPtr, JniHandleOwnership)

設定 Handle 屬性。

(繼承來源 Object)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
Split(ICharSequence, Int32)

將給定的輸入序列分割成與此模式匹配的部分。

Split(ICharSequence)

將給定的輸入序列分割成與此模式匹配的部分。

Split(String, Int32)

將給定的輸入序列分割成與此模式匹配的部分。

Split(String)

將給定的輸入序列分割成與此模式匹配的部分。

ToArray<T>()

從這個 Java 陣列包裝器建立一個受管理陣列。

(繼承來源 Object)
ToString()

回傳物件的字串表示。

(繼承來源 Object)
UnregisterFromRuntime()

將此 Java 節點從互通執行時中取消註冊。

(繼承來源 Object)
Wait()

導致目前執行緒等待被喚醒,通常是透過 <em>通知</><em 或 em>中斷</em> 來喚醒。

(繼承來源 Object)
Wait(Int64, Int32)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)
Wait(Int64)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)

明確介面實作

名稱 Description
IJavaPeerable.Disposed()

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.Finalized()

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)

一個正則表達式的編譯表示。

(繼承來源 JavaObject)
IJavaPeerable.UnregisterFromRuntime()

一個正則表達式的編譯表示。

擴充方法

名稱 Description
GetJniTypeName(IJavaPeerable)

取得實例 self類型的 JNI 名稱。

JavaAs<TResult>(IJavaPeerable)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

JavaCast<TResult>(IJavaObject)

執行 Android 執行時檢查型別轉換。

JavaCast<TResult>(IJavaObject)

一個正則表達式的編譯表示。

TryJavaCast<TResult>(IJavaPeerable, TResult)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

適用於