Pattern.java revision 4008
3261N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A compiled representation of a regular expression. 0N/A * <p> A regular expression, specified as a string, must first be compiled into 0N/A * an instance of this class. The resulting pattern can then be used to create 0N/A * a {@link Matcher} object that can match arbitrary {@link 0N/A * java.lang.CharSequence </code>character sequences<code>} against the regular 0N/A * expression. All of the state involved in performing a match resides in the 0N/A * matcher, so many matchers can share the same pattern. 0N/A * <p> A typical invocation sequence is thus 0N/A * Pattern p = Pattern.{@link #compile compile}("a*b"); 0N/A * Matcher m = p.{@link #matcher matcher}("aaaaab"); 0N/A * boolean b = m.{@link Matcher#matches matches}();</pre></blockquote> 0N/A * <p> A {@link #matches matches} method is defined by this class as a 0N/A * convenience for when a regular expression is used just once. This method 0N/A * compiles an expression and matches an input sequence against it in a single 0N/A * invocation. The statement 0N/A * boolean b = Pattern.matches("a*b", "aaaaab");</pre></blockquote> 0N/A * is equivalent to the three statements above, though for repeated matches it 0N/A * is less efficient since it does not allow the compiled pattern to be reused. 0N/A * <p> Instances of this class are immutable and are safe for use by multiple 0N/A * concurrent threads. Instances of the {@link Matcher} class are not safe for 0N/A * <h4> Summary of regular-expression constructs </h4> 0N/A * <table border="0" cellpadding="1" cellspacing="0" 0N/A * summary="Regular expression constructs, and what they match"> 0N/A * <th bgcolor="#CCCCFF" align="left" id="construct">Construct</th> 0N/A * <th bgcolor="#CCCCFF" align="left" id="matches">Matches</th> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="characters">Characters</th></tr> 0N/A * <tr><td valign="top" headers="construct characters"><i>x</i></td> 0N/A * <td headers="matches">The character <i>x</i></td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\\</tt></td> 0N/A * <td headers="matches">The backslash character</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>n</i></td> 0N/A * <td headers="matches">The character with octal value <tt>0</tt><i>n</i> 0N/A * (0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>nn</i></td> 0N/A * <td headers="matches">The character with octal value <tt>0</tt><i>nn</i> 0N/A * (0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>mnn</i></td> 0N/A * <td headers="matches">The character with octal value <tt>0</tt><i>mnn</i> 0N/A * (0 <tt><=</tt> <i>m</i> <tt><=</tt> 3, 0N/A * 0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\x</tt><i>hh</i></td> 0N/A * <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>hh</i></td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\u</tt><i>hhhh</i></td> 0N/A * <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>hhhh</i></td></tr> 3486N/A * <tr><td valign="top" headers="construct characters"><tt>\x</tt><i>{h...h}</i></td> 3486N/A * <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>h...h</i> 3486N/A * ({@link java.lang.Character#MIN_CODE_POINT Character.MIN_CODE_POINT} 3486N/A * <= <tt>0x</tt><i>h...h</i> <=  3486N/A * {@link java.lang.Character#MAX_CODE_POINT Character.MAX_CODE_POINT})</td></tr> 0N/A * <tr><td valign="top" headers="matches"><tt>\t</tt></td> 0N/A * <td headers="matches">The tab character (<tt>'\u0009'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\n</tt></td> 0N/A * <td headers="matches">The newline (line feed) character (<tt>'\u000A'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\r</tt></td> 0N/A * <td headers="matches">The carriage-return character (<tt>'\u000D'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\f</tt></td> 0N/A * <td headers="matches">The form-feed character (<tt>'\u000C'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\a</tt></td> 0N/A * <td headers="matches">The alert (bell) character (<tt>'\u0007'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\e</tt></td> 0N/A * <td headers="matches">The escape character (<tt>'\u001B'</tt>)</td></tr> 0N/A * <tr><td valign="top" headers="construct characters"><tt>\c</tt><i>x</i></td> 0N/A * <td headers="matches">The control character corresponding to <i>x</i></td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="classes">Character classes</th></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[abc]</tt></td> 0N/A * <td headers="matches"><tt>a</tt>, <tt>b</tt>, or <tt>c</tt> (simple class)</td></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[^abc]</tt></td> 0N/A * <td headers="matches">Any character except <tt>a</tt>, <tt>b</tt>, or <tt>c</tt> (negation)</td></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[a-zA-Z]</tt></td> 0N/A * <td headers="matches"><tt>a</tt> through <tt>z</tt> 0N/A * or <tt>A</tt> through <tt>Z</tt>, inclusive (range)</td></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[a-d[m-p]]</tt></td> 0N/A * <td headers="matches"><tt>a</tt> through <tt>d</tt>, 0N/A * or <tt>m</tt> through <tt>p</tt>: <tt>[a-dm-p]</tt> (union)</td></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[a-z&&[def]]</tt></td> 0N/A * <td headers="matches"><tt>d</tt>, <tt>e</tt>, or <tt>f</tt> (intersection)</tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[a-z&&[^bc]]</tt></td> 0N/A * <td headers="matches"><tt>a</tt> through <tt>z</tt>, 0N/A * except for <tt>b</tt> and <tt>c</tt>: <tt>[ad-z]</tt> (subtraction)</td></tr> 0N/A * <tr><td valign="top" headers="construct classes"><tt>[a-z&&[^m-p]]</tt></td> 0N/A * <td headers="matches"><tt>a</tt> through <tt>z</tt>, 0N/A * and not <tt>m</tt> through <tt>p</tt>: <tt>[a-lq-z]</tt>(subtraction)</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="predef">Predefined character classes</th></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>.</tt></td> 0N/A * <td headers="matches">Any character (may or may not match <a href="#lt">line terminators</a>)</td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\d</tt></td> 0N/A * <td headers="matches">A digit: <tt>[0-9]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\D</tt></td> 0N/A * <td headers="matches">A non-digit: <tt>[^0-9]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\s</tt></td> 0N/A * <td headers="matches">A whitespace character: <tt>[ \t\n\x0B\f\r]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\S</tt></td> 0N/A * <td headers="matches">A non-whitespace character: <tt>[^\s]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\w</tt></td> 0N/A * <td headers="matches">A word character: <tt>[a-zA-Z_0-9]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct predef"><tt>\W</tt></td> 0N/A * <td headers="matches">A non-word character: <tt>[^\w]</tt></td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="posix">POSIX character classes</b> (US-ASCII only)<b></th></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Lower}</tt></td> 0N/A * <td headers="matches">A lower-case alphabetic character: <tt>[a-z]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Upper}</tt></td> 0N/A * <td headers="matches">An upper-case alphabetic character:<tt>[A-Z]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{ASCII}</tt></td> 0N/A * <td headers="matches">All ASCII:<tt>[\x00-\x7F]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Alpha}</tt></td> 0N/A * <td headers="matches">An alphabetic character:<tt>[\p{Lower}\p{Upper}]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Digit}</tt></td> 0N/A * <td headers="matches">A decimal digit: <tt>[0-9]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Alnum}</tt></td> 0N/A * <td headers="matches">An alphanumeric character:<tt>[\p{Alpha}\p{Digit}]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Punct}</tt></td> 0N/A * <td headers="matches">Punctuation: One of <tt>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</tt></td></tr> 0N/A * <!-- <tt>[\!"#\$%&'\(\)\*\+,\-\./:;\<=\>\?@\[\\\]\^_`\{\|\}~]</tt> 0N/A * <tt>[\X21-\X2F\X31-\X40\X5B-\X60\X7B-\X7E]</tt> --> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Graph}</tt></td> 0N/A * <td headers="matches">A visible character: <tt>[\p{Alnum}\p{Punct}]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Print}</tt></td> 0N/A * <td headers="matches">A printable character: <tt>[\p{Graph}\x20]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Blank}</tt></td> 0N/A * <td headers="matches">A space or a tab: <tt>[ \t]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Cntrl}</tt></td> 0N/A * <td headers="matches">A control character: <tt>[\x00-\x1F\x7F]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{XDigit}</tt></td> 0N/A * <td headers="matches">A hexadecimal digit: <tt>[0-9a-fA-F]</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct posix"><tt>\p{Space}</tt></td> 0N/A * <td headers="matches">A whitespace character: <tt>[ \t\n\x0B\f\r]</tt></td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2">java.lang.Character classes (simple <a href="#jcc">java character type</a>)</th></tr> 0N/A * <tr><td valign="top"><tt>\p{javaLowerCase}</tt></td> 0N/A * <td>Equivalent to java.lang.Character.isLowerCase()</td></tr> 0N/A * <tr><td valign="top"><tt>\p{javaUpperCase}</tt></td> 0N/A * <td>Equivalent to java.lang.Character.isUpperCase()</td></tr> 0N/A * <tr><td valign="top"><tt>\p{javaWhitespace}</tt></td> 0N/A * <td>Equivalent to java.lang.Character.isWhitespace()</td></tr> 0N/A * <tr><td valign="top"><tt>\p{javaMirrored}</tt></td> 0N/A * <td>Equivalent to java.lang.Character.isMirrored()</td></tr> 0N/A * <tr><th> </th></tr> 2401N/A * <tr align="left"><th colspan="2" id="unicode">Classes for Unicode scripts, blocks and categories</th></tr> 2401N/A * * <tr><td valign="top" headers="construct unicode"><tt>\p{IsLatin}</tt></td> 2401N/A * <td headers="matches">A Latin script character (simple <a href="#ubc">script</a>)</td></tr> 0N/A * <tr><td valign="top" headers="construct unicode"><tt>\p{InGreek}</tt></td> 0N/A * <td headers="matches">A character in the Greek block (simple <a href="#ubc">block</a>)</td></tr> 0N/A * <tr><td valign="top" headers="construct unicode"><tt>\p{Lu}</tt></td> 0N/A * <td headers="matches">An uppercase letter (simple <a href="#ubc">category</a>)</td></tr> 0N/A * <tr><td valign="top" headers="construct unicode"><tt>\p{Sc}</tt></td> 0N/A * <td headers="matches">A currency symbol</td></tr> 0N/A * <tr><td valign="top" headers="construct unicode"><tt>\P{InGreek}</tt></td> 0N/A * <td headers="matches">Any character except one in the Greek block (negation)</td></tr> 0N/A * <tr><td valign="top" headers="construct unicode"><tt>[\p{L}&&[^\p{Lu}]] </tt></td> 0N/A * <td headers="matches">Any letter except an uppercase letter (subtraction)</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="bounds">Boundary matchers</th></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>^</tt></td> 0N/A * <td headers="matches">The beginning of a line</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>$</tt></td> 0N/A * <td headers="matches">The end of a line</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\b</tt></td> 0N/A * <td headers="matches">A word boundary</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\B</tt></td> 0N/A * <td headers="matches">A non-word boundary</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\A</tt></td> 0N/A * <td headers="matches">The beginning of the input</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\G</tt></td> 0N/A * <td headers="matches">The end of the previous match</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\Z</tt></td> 0N/A * <td headers="matches">The end of the input but for the final 0N/A * <a href="#lt">terminator</a>, if any</td></tr> 0N/A * <tr><td valign="top" headers="construct bounds"><tt>\z</tt></td> 0N/A * <td headers="matches">The end of the input</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="greedy">Greedy quantifiers</th></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>?</tt></td> 0N/A * <td headers="matches"><i>X</i>, once or not at all</td></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>*</tt></td> 0N/A * <td headers="matches"><i>X</i>, zero or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>+</tt></td> 0N/A * <td headers="matches"><i>X</i>, one or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>}</tt></td> 0N/A * <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>,}</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="reluc">Reluctant quantifiers</th></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>??</tt></td> 0N/A * <td headers="matches"><i>X</i>, once or not at all</td></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>*?</tt></td> 0N/A * <td headers="matches"><i>X</i>, zero or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>+?</tt></td> 0N/A * <td headers="matches"><i>X</i>, one or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>}?</tt></td> 0N/A * <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>,}?</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}?</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="poss">Possessive quantifiers</th></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>?+</tt></td> 0N/A * <td headers="matches"><i>X</i>, once or not at all</td></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>*+</tt></td> 0N/A * <td headers="matches"><i>X</i>, zero or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>++</tt></td> 0N/A * <td headers="matches"><i>X</i>, one or more times</td></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>}+</tt></td> 0N/A * <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>,}+</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr> 0N/A * <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}+</tt></td> 0N/A * <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="logical">Logical operators</th></tr> 0N/A * <tr><td valign="top" headers="construct logical"><i>XY</i></td> 0N/A * <td headers="matches"><i>X</i> followed by <i>Y</i></td></tr> 0N/A * <tr><td valign="top" headers="construct logical"><i>X</i><tt>|</tt><i>Y</i></td> 0N/A * <td headers="matches">Either <i>X</i> or <i>Y</i></td></tr> 0N/A * <tr><td valign="top" headers="construct logical"><tt>(</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches">X, as a <a href="#cg">capturing group</a></td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="backref">Back references</th></tr> 0N/A * <tr><td valign="bottom" headers="construct backref"><tt>\</tt><i>n</i></td> 0N/A * <td valign="bottom" headers="matches">Whatever the <i>n</i><sup>th</sup> 0N/A * <a href="#cg">capturing group</a> matched</td></tr> 906N/A * <tr><td valign="bottom" headers="construct backref"><tt>\</tt><i>k</i><<i>name</i>></td> 906N/A * <td valign="bottom" headers="matches">Whatever the 906N/A * <a href="#groupname">named-capturing group</a> "name" matched</td></tr> 0N/A * <tr><th> </th></tr> 0N/A * <tr align="left"><th colspan="2" id="quot">Quotation</th></tr> 0N/A * <tr><td valign="top" headers="construct quot"><tt>\</tt></td> 0N/A * <td headers="matches">Nothing, but quotes the following character</td></tr> 0N/A * <tr><td valign="top" headers="construct quot"><tt>\Q</tt></td> 0N/A * <td headers="matches">Nothing, but quotes all characters until <tt>\E</tt></td></tr> 0N/A * <tr><td valign="top" headers="construct quot"><tt>\E</tt></td> 0N/A * <td headers="matches">Nothing, but ends quoting started by <tt>\Q</tt></td></tr> 0N/A * <!-- Metachars: !$()*+.<>?[\]^{|} --> 0N/A * <tr><th> </th></tr> 906N/A * <tr align="left"><th colspan="2" id="special">Special constructs (named-capturing and non-capturing)</th></tr> 906N/A * <tr><td valign="top" headers="construct special"><tt>(?<<a href="#groupname">name</a>></tt><i>X</i><tt>)</tt></td> 906N/A * <td headers="matches"><i>X</i>, as a named-capturing group</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?:</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, as a non-capturing group</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?idmsux-idmsux) </tt></td> 0N/A * <td headers="matches">Nothing, but turns match flags <a href="#CASE_INSENSITIVE">i</a> 0N/A * <a href="#UNIX_LINES">d</a> <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a> 0N/A * <a href="#UNICODE_CASE">u</a> <a href="#COMMENTS">x</a> on - off</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?idmsux-idmsux:</tt><i>X</i><tt>)</tt> </td> 0N/A * <td headers="matches"><i>X</i>, as a <a href="#cg">non-capturing group</a> with the 0N/A * given flags <a href="#CASE_INSENSITIVE">i</a> <a href="#UNIX_LINES">d</a> 0N/A * <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a> <a href="#UNICODE_CASE">u</a > 0N/A * <a href="#COMMENTS">x</a> on - off</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?=</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, via zero-width positive lookahead</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?!</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, via zero-width negative lookahead</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?<=</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, via zero-width positive lookbehind</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?<!</tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, via zero-width negative lookbehind</td></tr> 0N/A * <tr><td valign="top" headers="construct special"><tt>(?></tt><i>X</i><tt>)</tt></td> 0N/A * <td headers="matches"><i>X</i>, as an independent, non-capturing group</td></tr> 0N/A * <h4> Backslashes, escapes, and quoting </h4> 0N/A * <p> The backslash character (<tt>'\'</tt>) serves to introduce escaped 0N/A * constructs, as defined in the table above, as well as to quote characters 0N/A * that otherwise would be interpreted as unescaped constructs. Thus the 0N/A * expression <tt>\\</tt> matches a single backslash and <tt>\{</tt> matches a 0N/A * <p> It is an error to use a backslash prior to any alphabetic character that 0N/A * does not denote an escaped construct; these are reserved for future 0N/A * extensions to the regular-expression language. A backslash may be used 0N/A * prior to a non-alphabetic character regardless of whether that character is 0N/A * part of an unescaped construct. 0N/A * <p> Backslashes within string literals in Java source code are interpreted 4008N/A * <cite>The Java™ Language Specification</cite> 4008N/A * as either Unicode escapes (section 3.3) or other character escapes (section 3.10.6) 4008N/A * It is therefore necessary to double backslashes in string 0N/A * literals that represent regular expressions to protect them from 0N/A * interpretation by the Java bytecode compiler. The string literal 0N/A * <tt>"\b"</tt>, for example, matches a single backspace character when 0N/A * interpreted as a regular expression, while <tt>"\\b"</tt> matches a 0N/A * word boundary. The string literal <tt>"\(hello\)"</tt> is illegal 0N/A * and leads to a compile-time error; in order to match the string 0N/A * <tt>(hello)</tt> the string literal <tt>"\\(hello\\)"</tt> 0N/A * <h4> Character Classes </h4> 0N/A * <p> Character classes may appear within other character classes, and 0N/A * may be composed by the union operator (implicit) and the intersection 0N/A * operator (<tt>&&</tt>). 0N/A * The union operator denotes a class that contains every character that is 0N/A * in at least one of its operand classes. The intersection operator 0N/A * denotes a class that contains every character that is in both of its 0N/A * <p> The precedence of character-class operators is as follows, from 0N/A * highest to lowest: 0N/A * <blockquote><table border="0" cellpadding="1" cellspacing="0" 0N/A * summary="Precedence of character class operators."> 0N/A * <tr><th>1 </th> 0N/A * <td>Literal escape </td> 0N/A * <td><tt>\x</tt></td></tr> 0N/A * <tr><th>2 </th> 0N/A * <td><tt>[...]</tt></td></tr> 0N/A * <tr><th>3 </th> 0N/A * <td><tt>a-z</tt></td></tr> 0N/A * <tr><th>4 </th> 0N/A * <td><tt>[a-e][i-u]</tt></td></tr> 0N/A * <tr><th>5 </th> 0N/A * <td>Intersection</td> 0N/A * <td><tt>[a-z&&[aeiou]]</tt></td></tr> 0N/A * </table></blockquote> 0N/A * <p> Note that a different set of metacharacters are in effect inside 0N/A * a character class than outside a character class. For instance, the 0N/A * regular expression <tt>.</tt> loses its special meaning inside a 0N/A * character class, while the expression <tt>-</tt> becomes a range 0N/A * forming metacharacter. 0N/A * <h4> Line terminators </h4> 0N/A * <p> A <i>line terminator</i> is a one- or two-character sequence that marks 0N/A * the end of a line of the input character sequence. The following are 0N/A * recognized as line terminators: 0N/A * <li> A newline (line feed) character (<tt>'\n'</tt>), 0N/A * <li> A carriage-return character followed immediately by a newline 0N/A * character (<tt>"\r\n"</tt>), 0N/A * <li> A standalone carriage-return character (<tt>'\r'</tt>), 0N/A * <li> A next-line character (<tt>'\u0085'</tt>), 0N/A * <li> A line-separator character (<tt>'\u2028'</tt>), or 0N/A * <li> A paragraph-separator character (<tt>'\u2029</tt>). 0N/A * <p>If {@link #UNIX_LINES} mode is activated, then the only line terminators 0N/A * recognized are newline characters. 0N/A * <p> The regular expression <tt>.</tt> matches any character except a line 0N/A * terminator unless the {@link #DOTALL} flag is specified. 0N/A * <p> By default, the regular expressions <tt>^</tt> and <tt>$</tt> ignore 0N/A * line terminators and only match at the beginning and the end, respectively, 0N/A * of the entire input sequence. If {@link #MULTILINE} mode is activated then 0N/A * <tt>^</tt> matches at the beginning of input and after any line terminator 0N/A * except at the end of input. When in {@link #MULTILINE} mode <tt>$</tt> 0N/A * matches just before a line terminator or the end of the input sequence. 0N/A * <h4> Groups and capturing </h4> 906N/A * <h5> Group number </h5> 0N/A * <p> Capturing groups are numbered by counting their opening parentheses from 0N/A * left to right. In the expression <tt>((A)(B(C)))</tt>, for example, there 0N/A * are four such groups: </p> 0N/A * <blockquote><table cellpadding=1 cellspacing=0 summary="Capturing group numberings"> 0N/A * <tr><th>1 </th> 0N/A * <td><tt>((A)(B(C)))</tt></td></tr> 0N/A * <tr><th>2 </th> 0N/A * <td><tt>(A)</tt></td></tr> 0N/A * <tr><th>3 </th> 0N/A * <td><tt>(B(C))</tt></td></tr> 0N/A * <tr><th>4 </th> 0N/A * <td><tt>(C)</tt></td></tr> 0N/A * </table></blockquote> 0N/A * <p> Group zero always stands for the entire expression. 0N/A * <p> Capturing groups are so named because, during a match, each subsequence 0N/A * of the input sequence that matches such a group is saved. The captured 0N/A * subsequence may be used later in the expression, via a back reference, and 0N/A * may also be retrieved from the matcher once the match operation is complete. 906N/A * <h5> Group name </h5> 906N/A * <p>A capturing group can also be assigned a "name", a <tt>named-capturing group</tt>, 906N/A * and then be back-referenced later by the "name". Group names are composed of 1795N/A * the following characters. The first character must be a <tt>letter</tt>. 906N/A * <li> The uppercase letters <tt>'A'</tt> through <tt>'Z'</tt> 906N/A * (<tt>'\u0041'</tt> through <tt>'\u005a'</tt>), 906N/A * <li> The lowercase letters <tt>'a'</tt> through <tt>'z'</tt> 906N/A * (<tt>'\u0061'</tt> through <tt>'\u007a'</tt>), 906N/A * <li> The digits <tt>'0'</tt> through <tt>'9'</tt> 906N/A * (<tt>'\u0030'</tt> through <tt>'\u0039'</tt>), 906N/A * <p> A <tt>named-capturing group</tt> is still numbered as described in 906N/A * <a href="#gnumber">Group number</a>. 0N/A * <p> The captured input associated with a group is always the subsequence 0N/A * that the group most recently matched. If a group is evaluated a second time 0N/A * because of quantification then its previously-captured value, if any, will 0N/A * be retained if the second evaluation fails. Matching the string 0N/A * <tt>"aba"</tt> against the expression <tt>(a(b)?)+</tt>, for example, leaves 0N/A * group two set to <tt>"b"</tt>. All captured input is discarded at the 0N/A * beginning of each match. 906N/A * <p> Groups beginning with <tt>(?</tt> are either pure, <i>non-capturing</i> groups 906N/A * that do not capture text and do not count towards the group total, or 906N/A * <i>named-capturing</i> group. 0N/A * <h4> Unicode support </h4> 0N/A * <p> This class is in conformance with Level 1 of <a 0N/A * Standard #18: Unicode Regular Expression Guidelines</i></a>, plus RL2.1 0N/A * Canonical Equivalents. 0N/A * <p> Unicode escape sequences such as <tt>\u2014</tt> in Java source code 4008N/A * are processed as described in section 3.3 of 4008N/A * <cite>The Java™ Language Specification</cite>. 4008N/A * Such escape sequences are also 0N/A * implemented directly by the regular-expression parser so that Unicode 0N/A * escapes can be used in expressions that are read from files or from the 0N/A * keyboard. Thus the strings <tt>"\u2014"</tt> and <tt>"\\u2014"</tt>, 0N/A * while not equal, compile into the same pattern, which matches the character 0N/A * with hexadecimal value <tt>0x2014</tt>. 3486N/A * <p> A Unicode character can also be represented in a regular-expression by 3486N/A * using its hexadecimal code point value directly as described in construct 3486N/A * <tt>\x{...}</tt>, for example a supplementary character U+2011F 3486N/A * can be specified as <tt>\x{2011F}</tt>, instead of two consecutive 3486N/A * Unicode escape sequences of the surrogate pair 3486N/A * <tt>\uD840</tt><tt>\uDD1F</tt>. 2401N/A * <p>Unicode scripts, blocks and categories are written with the <tt>\p</tt> and 2401N/A * <tt>\P</tt> constructs as in Perl. <tt>\p{</tt><i>prop</i><tt>}</tt> matches if 2401N/A * the input has the property <i>prop</i>, while <tt>\P{</tt><i>prop</i><tt>}</tt> 2401N/A * does not match if the input has that property. 2401N/A * Scripts are specified either with the prefix {@code Is}, as in 2401N/A * {@code IsHiragana}, or by using the {@code script} keyword (or its short 2401N/A * form {@code sc})as in {@code script=Hiragana} or {@code sc=Hiragana}. 2401N/A * Blocks are specified with the prefix {@code In}, as in 2401N/A * {@code InMongolian}, or by using the keyword {@code block} (or its short 2401N/A * form {@code blk}) as in {@code block=Mongolian} or {@code blk=Mongolian}. 2401N/A * Categories may be specified with the optional prefix {@code Is}: 2401N/A * Both {@code \p{L}} and {@code \p{IsL}} denote the category of Unicode 2401N/A * letters. Same as scripts and blocks, categories can also be specified 2401N/A * by using the keyword {@code general_category} (or its short form 2401N/A * {@code gc}) as in {@code general_category=Lu} or {@code gc=Lu}. 2401N/A * Scripts, blocks and categories can be used both inside and outside of a 0N/A * <p> The supported categories are those of 0N/A * <i>The Unicode Standard</i></a> in the version specified by the 0N/A * {@link java.lang.Character Character} class. The category names are those 0N/A * defined in the Standard, both normative and informative. 2401N/A * The script names supported by <code>Pattern</code> are the valid script names 2401N/A * {@link java.lang.Character.UnicodeScript#forName(String) UnicodeScript.forName}. 0N/A * The block names supported by <code>Pattern</code> are the valid block names 0N/A * accepted and defined by 0N/A * {@link java.lang.Character.UnicodeBlock#forName(String) UnicodeBlock.forName}. 0N/A * <a name="jcc"> <p>Categories that behave like the java.lang.Character 0N/A * boolean is<i>methodname</i> methods (except for the deprecated ones) are 0N/A * available through the same <tt>\p{</tt><i>prop</i><tt>}</tt> syntax where 0N/A * the specified property has the name <tt>java<i>methodname</i></tt>. 0N/A * <h4> Comparison to Perl 5 </h4> 0N/A * <p>The <code>Pattern</code> engine performs traditional NFA-based matching 0N/A * with ordered alternation as occurs in Perl 5. 0N/A * <p> Perl constructs not supported by this class: </p> 0N/A * <li><p> The conditional constructs <tt>(?{</tt><i>X</i><tt>})</tt> and 0N/A * <tt>(?(</tt><i>condition</i><tt>)</tt><i>X</i><tt>|</tt><i>Y</i><tt>)</tt>, 0N/A * <li><p> The embedded code constructs <tt>(?{</tt><i>code</i><tt>})</tt> 0N/A * and <tt>(??{</tt><i>code</i><tt>})</tt>,</p></li> 0N/A * <li><p> The embedded comment syntax <tt>(?#comment)</tt>, and </p></li> 0N/A * <li><p> The preprocessing operations <tt>\l</tt> <tt>\u</tt>, 0N/A * <tt>\L</tt>, and <tt>\U</tt>. </p></li> 0N/A * <p> Constructs supported by this class but not by Perl: </p> 0N/A * <li><p> Possessive quantifiers, which greedily match as much as they can 0N/A * and do not back off, even when doing so would allow the overall match to 0N/A * succeed. </p></li> 0N/A * <li><p> Character-class union and intersection as described 0N/A * <a href="#cc">above</a>.</p></li> 0N/A * <p> Notable differences from Perl: </p> 0N/A * <li><p> In Perl, <tt>\1</tt> through <tt>\9</tt> are always interpreted 0N/A * as back references; a backslash-escaped number greater than <tt>9</tt> is 0N/A * treated as a back reference if at least that many subexpressions exist, 0N/A * otherwise it is interpreted, if possible, as an octal escape. In this 0N/A * class octal escapes must always begin with a zero. In this class, 0N/A * <tt>\1</tt> through <tt>\9</tt> are always interpreted as back 0N/A * references, and a larger number is accepted as a back reference if at 0N/A * least that many subexpressions exist at that point in the regular 0N/A * expression, otherwise the parser will drop digits until the number is 0N/A * smaller or equal to the existing number of groups or it is one digit. 0N/A * <li><p> Perl uses the <tt>g</tt> flag to request a match that resumes 0N/A * where the last match left off. This functionality is provided implicitly 0N/A * by the {@link Matcher} class: Repeated invocations of the {@link 0N/A * Matcher#find find} method will resume where the last match left off, 0N/A * unless the matcher is reset. </p></li> 0N/A * <li><p> In Perl, embedded flags at the top level of an expression affect 0N/A * the whole expression. In this class, embedded flags always take effect 0N/A * at the point at which they appear, whether they are at the top level or 0N/A * within a group; in the latter case, flags are restored at the end of the 0N/A * group just as in Perl. </p></li> 0N/A * <li><p> Perl is forgiving about malformed matching constructs, as in the 0N/A * expression <tt>*a</tt>, as well as dangling brackets, as in the 0N/A * expression <tt>abc]</tt>, and treats them as literals. This 0N/A * class also accepts dangling brackets but is strict about dangling 0N/A * metacharacters like +, ? and *, and will throw a 0N/A * {@link PatternSyntaxException} if it encounters them. </p></li> 0N/A * <p> For a more precise description of the behavior of regular expression 0N/A * <i>Mastering Regular Expressions, 3nd Edition</i>, Jeffrey E. F. Friedl, 0N/A * O'Reilly and Associates, 2006.</a> 0N/A * @see java.lang.String#split(String, int) 0N/A * @see java.lang.String#split(String) 0N/A * @author Mike McCloskey 0N/A * @author Mark Reinhold 0N/A * @author JSR-51 Expert Group 0N/A * Regular expression modifier values. Instead of being passed as 0N/A * arguments, they can also be passed as inline modifiers. 0N/A * For example, the following statements have the same effect. 0N/A * RegExp r1 = RegExp.compile("abc", Pattern.I|Pattern.M); 0N/A * RegExp r2 = RegExp.compile("(?im)abc", 0); 0N/A * The flags are duplicated so that the familiar Perl match flag 0N/A * names are available. 0N/A * Enables Unix lines mode. 0N/A * <p> In this mode, only the <tt>'\n'</tt> line terminator is recognized 0N/A * in the behavior of <tt>.</tt>, <tt>^</tt>, and <tt>$</tt>. 0N/A * <p> Unix lines mode can also be enabled via the embedded flag 0N/A * expression <tt>(?d)</tt>. 0N/A * Enables case-insensitive matching. 0N/A * <p> By default, case-insensitive matching assumes that only characters 0N/A * in the US-ASCII charset are being matched. Unicode-aware 0N/A * case-insensitive matching can be enabled by specifying the {@link 0N/A * #UNICODE_CASE} flag in conjunction with this flag. 0N/A * <p> Case-insensitive matching can also be enabled via the embedded flag 0N/A * expression <tt>(?i)</tt>. 0N/A * <p> Specifying this flag may impose a slight performance penalty. </p> 0N/A * Permits whitespace and comments in pattern. 0N/A * <p> In this mode, whitespace is ignored, and embedded comments starting 0N/A * with <tt>#</tt> are ignored until the end of a line. 0N/A * <p> Comments mode can also be enabled via the embedded flag 0N/A * expression <tt>(?x)</tt>. 0N/A * Enables multiline mode. 0N/A * <p> In multiline mode the expressions <tt>^</tt> and <tt>$</tt> match 0N/A * just after or just before, respectively, a line terminator or the end of 0N/A * the input sequence. By default these expressions only match at the 0N/A * beginning and the end of the entire input sequence. 0N/A * <p> Multiline mode can also be enabled via the embedded flag 0N/A * expression <tt>(?m)</tt>. </p> 0N/A * Enables literal parsing of the pattern. 0N/A * <p> When this flag is specified then the input string that specifies 0N/A * the pattern is treated as a sequence of literal characters. 0N/A * Metacharacters or escape sequences in the input sequence will be 0N/A * given no special meaning. 0N/A * <p>The flags CASE_INSENSITIVE and UNICODE_CASE retain their impact on 0N/A * matching when used in conjunction with this flag. The other flags 0N/A * become superfluous. 0N/A * <p> There is no embedded flag character for enabling literal parsing. 0N/A * Enables dotall mode. 0N/A * <p> In dotall mode, the expression <tt>.</tt> matches any character, 0N/A * including a line terminator. By default this expression does not match 0N/A * <p> Dotall mode can also be enabled via the embedded flag 0N/A * expression <tt>(?s)</tt>. (The <tt>s</tt> is a mnemonic for 0N/A * "single-line" mode, which is what this is called in Perl.) </p> 0N/A * Enables Unicode-aware case folding. 0N/A * <p> When this flag is specified then case-insensitive matching, when 0N/A * enabled by the {@link #CASE_INSENSITIVE} flag, is done in a manner 0N/A * consistent with the Unicode Standard. By default, case-insensitive 0N/A * matching assumes that only characters in the US-ASCII charset are being 0N/A * <p> Unicode-aware case folding can also be enabled via the embedded flag 0N/A * expression <tt>(?u)</tt>. 0N/A * <p> Specifying this flag may impose a performance penalty. </p> 0N/A * Enables canonical equivalence. 0N/A * <p> When this flag is specified then two characters will be considered 0N/A * to match if, and only if, their full canonical decompositions match. 0N/A * The expression <tt>"a\u030A"</tt>, for example, will match the 0N/A * string <tt>"\u00E5"</tt> when this flag is specified. By default, 0N/A * matching does not take canonical equivalence into account. 0N/A * <p> There is no embedded flag character for enabling canonical 0N/A * <p> Specifying this flag may impose a performance penalty. </p> 0N/A /* Pattern has only two serialized components: The pattern string 0N/A * and the flags, which are all that is needed to recompile the pattern 0N/A * when it is deserialized. 0N/A /** use serialVersionUID from Merlin b59 for interoperability */ 0N/A * The original regular-expression pattern string. 0N/A * The original pattern flags. 0N/A * Boolean indicating this Pattern is compiled; this is necessary in order 0N/A * to lazily compile deserialized Patterns. 0N/A * The normalized pattern string. 0N/A * The starting point of state machine for the find operation. This allows 0N/A * a match to start anywhere in the input. 0N/A * The root of object tree for a match operation. The pattern is matched 0N/A * at the beginning. This may include a find that uses BnM or a First 0N/A * Temporary storage used by parsing pattern slice. 906N/A * Map the "name" of the "named capturing group" to its group id 0N/A * Temporary storage used while parsing group references. 0N/A * Temporary null terminated code point array used by pattern compiling. 0N/A * The number of capturing groups in this Pattern. Used by matchers to 0N/A * allocate storage needed to perform a match. 0N/A * The local variable count used by parsing tree. Used by matchers to 0N/A * allocate storage needed to perform a match. 0N/A * Index into the pattern string that keeps track of how much has been 0N/A * Holds the length of the pattern string. 2118N/A * If the Start node might possibly match supplementary characters. 2118N/A * It is set to true during compiling if 2118N/A * (1) There is supplementary char in pattern, or 2118N/A * (2) There is complement node of Category or Block 0N/A * Compiles the given regular expression into a pattern. </p> 0N/A * The expression to be compiled 0N/A * @throws PatternSyntaxException 0N/A * If the expression's syntax is invalid 0N/A * Compiles the given regular expression into a pattern with the given 0N/A * The expression to be compiled 0N/A * Match flags, a bit mask that may include 0N/A * {@link #CASE_INSENSITIVE}, {@link #MULTILINE}, {@link #DOTALL}, 0N/A * {@link #UNICODE_CASE}, {@link #CANON_EQ}, {@link #UNIX_LINES}, 0N/A * {@link #LITERAL} and {@link #COMMENTS} 0N/A * @throws IllegalArgumentException 0N/A * If bit values other than those corresponding to the defined 0N/A * match flags are set in <tt>flags</tt> 0N/A * @throws PatternSyntaxException 0N/A * If the expression's syntax is invalid 0N/A * Returns the regular expression from which this pattern was compiled. 0N/A * @return The source of this pattern 0N/A * <p>Returns the string representation of this pattern. This 0N/A * is the regular expression from which this pattern was 0N/A * @return The string representation of this pattern 0N/A * Creates a matcher that will match the given input against this pattern. 0N/A * The character sequence to be matched 0N/A * @return A new matcher for this pattern 0N/A synchronized(
this) {
0N/A * Returns this pattern's match flags. </p> 0N/A * @return The match flags specified when this pattern was compiled 0N/A * Compiles the given regular expression and attempts to match the given 0N/A * <p> An invocation of this convenience method of the form 0N/A * Pattern.matches(regex, input);</pre></blockquote> 0N/A * behaves in exactly the same way as the expression 0N/A * Pattern.compile(regex).matcher(input).matches()</pre></blockquote> 0N/A * <p> If a pattern is to be used multiple times, compiling it once and reusing 0N/A * it will be more efficient than invoking this method each time. </p> 0N/A * The expression to be compiled 0N/A * The character sequence to be matched 0N/A * @throws PatternSyntaxException 0N/A * If the expression's syntax is invalid 0N/A * Splits the given input sequence around matches of this pattern. 0N/A * <p> The array returned by this method contains each substring of the 0N/A * input sequence that is terminated by another subsequence that matches 0N/A * this pattern or is terminated by the end of the input sequence. The 0N/A * substrings in the array are in the order in which they occur in the 0N/A * input. If this pattern does not match any subsequence of the input then 0N/A * the resulting array has just one element, namely the input sequence in 0N/A * <p> The <tt>limit</tt> parameter controls the number of times the 0N/A * pattern is applied and therefore affects the length of the resulting 0N/A * array. If the limit <i>n</i> is greater than zero then the pattern 0N/A * will be applied at most <i>n</i> - 1 times, the array's 0N/A * length will be no greater than <i>n</i>, and the array's last entry 0N/A * will contain all input beyond the last matched delimiter. If <i>n</i> 0N/A * is non-positive then the pattern will be applied as many times as 0N/A * possible and the array can have any length. If <i>n</i> is zero then 0N/A * the pattern will be applied as many times as possible, the array can 0N/A * have any length, and trailing empty strings will be discarded. 0N/A * <p> The input <tt>"boo:and:foo"</tt>, for example, yields the following 0N/A * results with these parameters: 0N/A * <blockquote><table cellpadding=1 cellspacing=0 0N/A * summary="Split examples showing regex, limit, and result"> 0N/A * <tr><th><P align="left"><i>Regex </i></th> 0N/A * <th><P align="left"><i>Limit </i></th> 0N/A * <th><P align="left"><i>Result </i></th></tr> 0N/A * <tr><td align=center>:</td> 0N/A * <td align=center>2</td> 0N/A * <td><tt>{ "boo", "and:foo" }</tt></td></tr> 0N/A * <tr><td align=center>:</td> 0N/A * <td align=center>5</td> 0N/A * <td><tt>{ "boo", "and", "foo" }</tt></td></tr> 0N/A * <tr><td align=center>:</td> 0N/A * <td align=center>-2</td> 0N/A * <td><tt>{ "boo", "and", "foo" }</tt></td></tr> 0N/A * <tr><td align=center>o</td> 0N/A * <td align=center>5</td> 0N/A * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr> 0N/A * <tr><td align=center>o</td> 0N/A * <td align=center>-2</td> 0N/A * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr> 0N/A * <tr><td align=center>o</td> 0N/A * <td align=center>0</td> 0N/A * <td><tt>{ "b", "", ":and:f" }</tt></td></tr> 0N/A * </table></blockquote> 0N/A * The character sequence to be split 0N/A * The result threshold, as described above 0N/A * @return The array of strings computed by splitting the input 0N/A * around matches of this pattern 0N/A // Add segments before each match found 0N/A // If no match was found, return this 0N/A // Add remaining segment 0N/A * Splits the given input sequence around matches of this pattern. 0N/A * <p> This method works as if by invoking the two-argument {@link 0N/A * #split(java.lang.CharSequence, int) split} method with the given input 0N/A * sequence and a limit argument of zero. Trailing empty strings are 0N/A * therefore not included in the resulting array. </p> 0N/A * <p> The input <tt>"boo:and:foo"</tt>, for example, yields the following 0N/A * results with these expressions: 0N/A * <blockquote><table cellpadding=1 cellspacing=0 0N/A * summary="Split examples showing regex and result"> 0N/A * <tr><th><P align="left"><i>Regex </i></th> 0N/A * <th><P align="left"><i>Result</i></th></tr> 0N/A * <tr><td align=center>:</td> 0N/A * <td><tt>{ "boo", "and", "foo" }</tt></td></tr> 0N/A * <tr><td align=center>o</td> 0N/A * <td><tt>{ "b", "", ":and:f" }</tt></td></tr> 0N/A * </table></blockquote> 0N/A * The character sequence to be split 0N/A * @return The array of strings computed by splitting the input 0N/A * around matches of this pattern 0N/A * Returns a literal pattern <code>String</code> for the specified 0N/A * <code>String</code>. 0N/A * <p>This method produces a <code>String</code> that can be used to 0N/A * create a <code>Pattern</code> that would match the string 0N/A * <code>s</code> as if it were a literal pattern.</p> Metacharacters 0N/A * or escape sequences in the input sequence will be given no special 0N/A * @param s The string to be literalized 0N/A * @return A literal string replacement 0N/A return "\\Q" + s +
"\\E";
0N/A * Recompile the Pattern instance from a stream. The original pattern 0N/A * string is read in and the object tree is recompiled from it. 0N/A // Read in all fields 0N/A // Initialize counts 0N/A // if length > 0, the Pattern is lazily compiled 0N/A * This private constructor is used to create all Patterns. The pattern 0N/A * string and match flags are all that is needed to completely describe 0N/A * a Pattern. An empty pattern string results in an object tree with 0N/A * only a Start node and a LastNode node. 0N/A // Reset group index count 0N/A * The pattern is converted to normalizedD form and then a pure group 0N/A * is constructed to match canonical equivalences of the characters. 0N/A // Convert pattern into normalizedD form 0N/A // Modify pattern to match canonical equivalences 0N/A * Complete the character class being parsed and add a set 0N/A * of alternations to it that will match the canonical equivalences 0N/A * of the characters within the class. 0N/A throw error(
"Unclosed character class");
0N/A * Given a specific sequence composed of a regular character and 0N/A * combining marks that follow it, produce the alternation that will 0N/A * match all canonical equivalences of that sequence. 0N/A // source has one character. 0N/A // Add combined permutations 0N/A * Returns an array of strings that have all the possible 0N/A * permutations of the characters in the input string. 0N/A * This is used to get a list of all possible orderings 0N/A * of a set of combining marks. Note that some of the permutations 0N/A * are invalid because of combining class collisions, and these 0N/A * possibilities must be removed because they are not canonically 0N/A // For each char, take it out and add the permutations 0N/A // of the remaining chars 0N/A // offset maintains the index in code units. 0N/A for(
int y=x-
1; y>=
0; y--) {
0N/A * Attempts to compose input by combining the first character 0N/A * with the first combining mark following it. Returns a String 0N/A * that is the composition of the leading character with its first 0N/A * combining mark followed by the remaining combining marks. Returns 0N/A * null if the first two characters cannot be further composed. 0N/A * Preprocess any \Q...\E sequences in `temp', meta-quoting them. 0N/A * See the description of `quotemeta' in perlfunc(1). 0N/A if (i >=
pLen -
1)
// No \Q sequence found 0N/A }
else if (c !=
'\\') {
0N/A * Copies regular expression to an int array and invokes the parsing 0N/A * of the expression which will create the object tree. 0N/A // Handle canonical equivalences 0N/A // Copy pattern to int array for convenience 0N/A // Use double zero to terminate pattern 0N/A // Convert all chars into code points 0N/A // Allocate all temporary objects here. 0N/A // Literal pattern handling 0N/A // Start recursive descent parsing 0N/A // Check extra pattern characters 0N/A throw error(
"Unexpected internal error");
0N/A // Peephole optimization 0N/A // Release temporary storage 0N/A * Used to print out a subtree of the Pattern to help with debugging. 0N/A * Used to accumulate information about a subtree of the object graph 0N/A * so that optimizations can be applied to the subtree. 0N/A * The following private methods are mainly used to improve the 0N/A * readability of the code. In order to let the Java compiler easily 0N/A * inline them, we should not put many assertions or error checks in them. 0N/A * Indicates whether a particular flag is set or not. 0N/A * Match next character, signal error if failed. 0N/A * Mark the end of pattern with a specific character. 0N/A * Peek the next character, and do not advance the cursor. 0N/A * Read the next character, and advance the cursor by one. 0N/A * Read the next character, and advance the cursor by one, 0N/A * ignoring the COMMENTS setting 0N/A * Advance the cursor by one, and peek the next character. 0N/A * Advance the cursor by one, and peek the next character, 0N/A * ignoring the COMMENTS setting 0N/A * If in xmode peek past whitespace and comments. 0N/A * If in xmode parse past whitespace and comments. 0N/A * xmode parse past comment to end of line. 0N/A * xmode peek past comment to end of line. 0N/A * Determines if character is a line separator in the current mode 0N/A * Read the character after the next one, and advance the cursor by two. 0N/A * Unread one next character, and retreat cursor by one. 0N/A * Internal method used for handling all syntax errors. The pattern is 0N/A * displayed with a pointer to aid in locating the syntax error. 0N/A * Determines if there is any supplementary character or unpaired 0N/A * surrogate in the specified range. 0N/A * Determines if the specified code point is a supplementary 0N/A * character or unpaired surrogate. 0N/A * The following methods handle the main parsing. They are sorted 0N/A * according to their precedence order, the lowest one first. 0N/A * The expression is parsed with branch nodes added for alternations. 0N/A * This may be called recursively to parse sub expressions that may 0N/A * contain alternations. 0N/A // if the node returned from sequence() is "end" 0N/A // we have an empty expr, set a null atom into 0N/A // the branch to indicate to go "next" directly. 0N/A // the "tail.next" of each atom goes to branchConn 0N/A // replace the "end" with "branchConn" at its tail.next 0N/A // when put the "prev" into the branch as the first atom. 0N/A * Parsing of sequences between alternations. 0N/A // Because group handles its own closure, 0N/A // we need to treat it differently 0N/A // Check for comment or flag group 0N/A // Double return: Tail was returned in root 0N/A case ']':
// Now interpreting dangling ] and } as literals 0N/A throw error(
"Dangling meta character '" + ((
char)
ch) +
"'");
0N/A * Parse and add a new Single or Slice. 0N/A if (
ch ==
'p' ||
ch ==
'P') {
// Property 0N/A if (
first >
0) {
// Slice is waiting; handle it first 0N/A }
else {
// No slice; just return the family node 0N/A // Unwind meta escape sequence 0N/A * Parses a backref greedily, taking as many numbers as it 0N/A * can. The first digit is always treated as a backref, but 0N/A * multi digit numbers are only treated as a backref if at 0N/A * least that many backrefs exist at this point in the regex. 0N/A // Add another number if it doesn't make a group 0N/A // that doesn't exist 0N/A * Parses an escape sequence to determine the actual value that needs 0N/A * If -1 is returned and create was true a new object was added to the tree 0N/A * to handle the escape sequence. 0N/A * If the returned value is greater than zero, it is the value that 0N/A * matches the escape sequence. 906N/A throw error(
"\\k is not followed by '<' for named capturing group");
0N/A * Parse a character class, and return the node that matches it. 0N/A * Consumes a ] on the way out if consume is true. Usually consume 0N/A * is true except for the case of [abc&&def] where def is a separate 0N/A * right hand node with "understood" brackets. 0N/A // Negates if first char in a class, otherwise literal 0N/A // ^ not first in class, treat as literal 0N/A }
else {
// abc&&def 0N/A // treat as a literal & 0N/A throw error(
"Unclosed character class");
0N/A /* Bits can only handle codepoints in [u+0000-u+00ff] range. 0N/A Use "single" node instead of bits when dealing with unicode 0N/A case folding for codepoints listed below. 0N/A (1)Uppercase out of range: u+00ff, u+00b5 0N/A toUpperCase(u+00ff) -> u+0178 0N/A toUpperCase(u+00b5) -> u+039c 0N/A (2)LatinSmallLetterLongS u+17f 0N/A toUpperCase(u+017f) -> u+0053 0N/A (3)LatinSmallLetterDotlessI u+131 0N/A toUpperCase(u+0131) -> u+0049 0N/A (4)LatinCapitalLetterIWithDotAbove u+0130 0N/A toLowerCase(u+0130) -> u+0069 0N/A (5)KelvinSign u+212a 0N/A toLowerCase(u+212a) ==> u+006B 0N/A (6)AngstromSign u+212b 0N/A toLowerCase(u+212b) ==> u+00e5 0N/A ch ==
0x49 ||
ch ==
0x69 ||
//I and i 0N/A ch ==
0x53 ||
ch ==
0x73 ||
//S and s 0N/A ch ==
0x4b ||
ch ==
0x6b ||
//K and k 0N/A ch ==
0xc5 ||
ch ==
0xe5)))
//A+ring 0N/A * Parse a single character or a character range in a character class 0N/A * and return its representative node. 0N/A if (
ch ==
'p' ||
ch ==
'P') {
// A property 0N/A // Consume { if present 0N/A }
else {
// ordinary escape 0N/A throw error(
"Unexpected character '"+((
char)
ch)+
"'");
0N/A * Parses a Unicode character family and returns its representative node. 0N/A throw error(
"Unclosed character family");
2401N/A // property construct \p{name=value} 2401N/A // \p{isGeneralCategory} and \p{isScriptName} 2401N/A * Returns a CharProperty matching all characters belong to 0N/A * Returns a CharProperty matching all characters in a UnicodeBlock. 0N/A * Returns a CharProperty matching all characters in a named property. 0N/A throw error(
"Unknown character property name {" +
name +
"}");
906N/A * Parses and returns the name of a "named capturing group", the trailing 906N/A * ">" is consumed after parsing. 906N/A throw error(
"named capturing group has 0 length name");
906N/A throw error(
"named capturing group is missing trailing '>'");
0N/A * Parses a group and returns the head node of a set of nodes that process 0N/A * the group. Sometimes a double return system is used where the tail is 0N/A case ':':
// (?:xxx) pure group 0N/A case '=':
// (?=xxx) and (?!xxx) lookahead 0N/A case '>':
// (?>xxx) independent group 0N/A case '<':
// (?<xxx) look behind 960N/A // named captured group 906N/A +
"> is already defined");
0N/A throw error(
"Look-behind group does not have " 0N/A +
"an obvious maximum length");
0N/A throw error(
"Unknown look-behind group");
0N/A default:
// (?xxx:) inlined match flags 0N/A return null;
// Inline modifier only 0N/A }
else {
// (xxx) a regular group 0N/A // Check for quantifiers 0N/A }
else {
// Reluctant quantifier 0N/A // Discover if the group is deterministic 0N/A }
else {
// Non-deterministic 0N/A else // Reluctant Curly 0N/A * Create group head and tail nodes using double return. If the group is 0N/A * created with anonymous true then it is a pure group and should not 0N/A * affect group counting. 0N/A * Parses inlined match flags and set them appropriately. 0N/A case '-':
// subFlag then fall through 0N/A * Parses the second part of inlined match flags and turns off 0N/A * flags appropriately. 0N/A * Processes repetition. If the next character peeked is a quantifier 0N/A * then new nodes must be appended to handle the repetition. 0N/A * Prev could be a single or a group, so it could be a chain of nodes. 0N/A throw error(
"Unclosed counted closure");
0N/A throw error(
"Illegal repetition range");
0N/A * Utility method for parsing control escape sequences. 0N/A throw error(
"Illegal control escape sequence");
0N/A * Utility method for parsing octal escape sequences. 0N/A if (((n-
'0')|(
'7'-n)) >=
0) {
0N/A if (((m-
'0')|(
'7'-m)) >=
0) {
0N/A if ((((o-
'0')|(
'7'-o)) >=
0) && (((n-
'0')|(
'3'-n)) >=
0)) {
0N/A return (n -
'0') *
64 + (m -
'0') *
8 + (o -
'0');
0N/A return (n -
'0') *
8 + (m -
'0');
0N/A throw error(
"Illegal octal escape sequence");
0N/A * Utility method for parsing hexadecimal escape sequences. 3486N/A throw error(
"Unclosed hexadecimal escape sequence");
0N/A throw error(
"Illegal hexadecimal escape sequence");
0N/A * Utility method for parsing unicode escape sequences. 0N/A for (
int i =
0; i <
4; i++) {
0N/A throw error(
"Illegal Unicode escape sequence");
0N/A // Utility methods for code point support 0N/A for (
int i =
0; x >
0 && i <
len; i++) {
0N/A * Creates a bit vector for matching Latin-1 values. A normal BitClass 0N/A * never matches values above Latin-1, and a complemented BitClass always 0N/A * matches values above Latin-1. 0N/A assert c >=
0 && c <=
255;
0N/A * Returns a suitably optimized, single character matcher. 0N/A * Utility method for creating a string slice matcher. 0N/A * The following classes are the building components of the object 0N/A * tree that represents a compiled regular expression. The object tree 0N/A * is made of individual elements that handle constructs in the Pattern. 0N/A * Each type of object knows how to match its equivalent construct with 0N/A * the match() method. 0N/A * Base class for all node classes. Subclasses should override the match() 0N/A * method as appropriate. This class is an accepting node, so its match() 0N/A * always returns true. 0N/A * This method implements the classic accept node. 0N/A * This method is good for all zero length assertions. 0N/A * This method implements the classic accept node with 0N/A * the addition of a check to see if the match occurred 0N/A * using all of the input. 0N/A * Used for REs that can start anywhere within the input string. 0N/A * This basically tries to match repeatedly at each spot in the 0N/A * input string, moving forward after each try. An anchored search 0N/A * or a BnM will bypass this node completely. 0N/A * StartS supports supplementary characters, including unpaired surrogates. 2118N/A //if ((ret = next.match(matcher, i, seq)) || i == guard) 0N/A // Optimization to move to the next character. This is 0N/A // faster than countChars(seq, i, 1). 0N/A * Node to anchor at the beginning of input. This object implements the 0N/A * match for a \A sequence, and the caret anchor will use this if not in 0N/A * Node to anchor at the end of input. This is the absolute end, so this 0N/A * should not match at the last newline before the end as $ will. 0N/A * Node to anchor at the beginning of a line. This is essentially the 0N/A * object to match for the multiline ^. 0N/A // Perl does not match ^ at end of input even after newline 0N/A // Should treat /r/n as one newline 0N/A * Node to anchor at the beginning of a line when in unixdot mode. 0N/A // Perl does not match ^ at end of input even after newline 0N/A * Node to match the location where the last match ended. 0N/A * This is used for the \G construct. 0N/A * Node to anchor at the end of a line or the end of input based on the 0N/A * When not in multiline mode, the $ can only match at the very end 0N/A * of the input, unless the input ends in a line terminator in which 0N/A * it matches right before the last line terminator. 0N/A * Note that \r\n is considered an atomic line terminator. 0N/A * Like ^ the $ operator matches at a position, it does not match the 0N/A * line terminators themselves. 0N/A // Matches before any line terminator; also matches at the 0N/A // Before line terminator: 0N/A // If multiline, we match here no matter what 0N/A // If not multiline, fall through so that the end 0N/A // is marked as hit; this must be a /r/n or a /n 0N/A // at the very end so the end was hit; more input 0N/A // could make this not match here 0N/A // No match between \r\n 0N/A }
else if (
ch ==
'\r' ||
ch ==
'\u0085' ||
0N/A }
else {
// No line terminator, no match 0N/A // Matched at current end so hit end 0N/A // If a $ matches because of end of input, then more input 0N/A // could cause it to fail! 0N/A * Node to anchor at the end of a line or the end of input based on the 0N/A * multiline mode when in unix lines mode. 0N/A // If not multiline, then only possible to 0N/A // match at very end or one before end 0N/A // If multiline return next.match without setting 0N/A // Matching because at the end or 1 before the end; 0N/A // more input could change this so set hitEnd 0N/A // If a $ matches because of end of input, then more input 0N/A // could cause it to fail! 0N/A * Abstract node class to match one character satisfying some 0N/A * Optimized version of CharProperty that works only for 0N/A * properties never satisfied by Supplementary characters. 0N/A * Node class that matches a Supplementary Unicode character 0N/A * Optimization -- matches a given BMP character 0N/A * Case insensitive matches a given BMP character 0N/A * Unicode case insensitive matches a given Unicode character 2118N/A * Node class that matches a Unicode block. 2401N/A * Node class that matches a Unicode script 0N/A * Node class that matches a Unicode category. 0N/A * Node class that matches a POSIX type. 0N/A * Base class for all Slice nodes 0N/A * literal characters. Uses unicode case folding. 0N/A * Node class for a case sensitive sequence of literal characters 0N/A * including supplementary characters. 0N/A * Node class for a case insensitive sequence of literal characters 0N/A * including supplementary characters. 0N/A * Node class for a case insensitive sequence of literal characters. 0N/A * Uses unicode case folding. 0N/A * Returns node for matching characters within an explicit value range. 0N/A * Returns node for matching characters within an explicit value 0N/A * range in a case insensitive manner. 0N/A * Implements the Unicode category ALL and the dot metacharacter when 0N/A * Node class for the dot metacharacter when dotall is not enabled. 0N/A * Node class for the dot metacharacter when dotall is not enabled 0N/A * but UNIX_LINES is enabled. 0N/A * The 0 or 1 quantifier. This one class implements all three types. 0N/A * Handles the curly-brace style repetition with a specified minimum and 0N/A * maximum occurrences. The * quantifier is handled as a special case. 0N/A * This class handles the three types. 0N/A // i is the index to start matching at 0N/A // j is the number of atoms that have matched 0N/A // We have matched the maximum... continue with the rest of 0N/A // the regular expression 0N/A // k is the length of this match 0N/A if (k ==
0)
// Zero length match 0N/A // Move up index and number matched 0N/A // We are greedy so match as many as we can 0N/A // Handle backing off if match fails 0N/A // Reluctant match. At this point, the minimum has been satisfied. 0N/A // i is the index to start matching at 0N/A // j is the number of atoms that have matched 0N/A // Try finishing match without consuming any more 0N/A // At the maximum, no match found 0N/A // Okay, must try one more atom 0N/A // If we haven't moved forward then must break out 0N/A // Move up index and number matched 0N/A // Save original info 0N/A temp =
0xFFFFFFF;
// arbitrary large number 0N/A * Handles the curly-brace style repetition with a specified minimum and 0N/A * maximum occurrences in deterministic cases. This is an iterative 0N/A * optimization over the Prolog and Loop system which would handle this 0N/A * in a recursive way. The * quantifier is handled as a special case. 0N/A * If capture is true then this class saves group settings and ensures 0N/A * that groups are unset when backing off of a group match. 0N/A // Notify GroupTail there is no need to setup group info 0N/A // because it will be set here 0N/A // Aggressive group match 0N/A // Reluctant matching 0N/A // Possessive matching 0N/A // Save original info 0N/A temp =
0xFFFFFFF;
// Arbitrary large number 0N/A * A Guard node at the end of each atom node in a Branch. It 0N/A * serves the purpose of chaining the "match" operation to 0N/A * "next" but not the "study", so we can collect the TreeInfo 0N/A * of each atom node without including the TreeInfo of the 0N/A * Handles the branching of alternations. Note this is also used for 0N/A * the ? quantifier to branch between the case where it matches once 0N/A * and where it does not occur. 0N/A * The GroupHead saves the location where the group begins in the locals 0N/A * and restores them when the match is done. 0N/A * The matchRef is used when a reference to this group is accessed later 0N/A * in the expression. The locals will have a negative value in them to 0N/A * indicate that we do not want to unset the group if the reference 0N/A * Recursive reference to a group in the regular expression. It calls 0N/A * matchRef because if the reference fails to match we would not unset 0N/A * The GroupTail handles the setting of group beginning and ending 0N/A * locations when groups are successfully matched. It must also be able to 0N/A * unset groups that have to be backed off of. 0N/A * The GroupTail node is also used when a previous group is referenced, 0N/A * and in that case no group information needs to be set. 0N/A if (
tmp >=
0) {
// This is the normal group case. 0N/A // Save the group so we can unset it if it 0N/A // backs off of a match. 0N/A // This is a group reference case. We don't need to save any 0N/A // group info because it isn't really a group. 0N/A * This sets up a loop to handle a recursive quantifier structure. 0N/A * Handles the repetition count for a greedy Curly. The matchInit 0N/A * is called from the Prolog to save the index of where the group 0N/A * beginning is stored. A zero length group check occurs in the 0N/A * normal match but is skipped in the matchInit. 0N/A // Avoid infinite loop in zero-length case. 0N/A // This block is for before we reach the minimum 0N/A // iterations required for the loop to match 0N/A // If match failed we must backtrack, so 0N/A // the loop count should NOT be incremented 0N/A // Return success or failure since we are under 0N/A // This block is for after we have the minimum 0N/A // iterations required for the loop to match 0N/A // If match failed we must backtrack, so 0N/A // the loop count should NOT be incremented 0N/A * Handles the repetition count for a reluctant Curly. The matchInit 0N/A * is called from the Prolog to save the index of where the group 0N/A * beginning is stored. A zero length group check occurs in the 0N/A * normal match but is skipped in the matchInit. 0N/A // Check for zero length group 0N/A // If match failed we must backtrack, so 0N/A // the loop count should NOT be incremented 0N/A // If match failed we must backtrack, so 0N/A // the loop count should NOT be incremented 0N/A * Refers to a group in the regular expression. Attempts to match 0N/A * whatever the group referred to last matched. 0N/A // If the referenced group didn't match, neither can this 0N/A // If there isn't enough input left no match 0N/A // Check each new char to make sure it matches what the group 0N/A // referenced matched last time around 0N/A // If the referenced group didn't match, neither can this 0N/A // If there isn't enough input left no match 0N/A // Check each new char to make sure it matches what the group 0N/A // referenced matched last time around 0N/A * Searches until the next instance of its atom. This is useful for 0N/A * finding the atom efficiently without passing an instance of it 0N/A * (greedy problem) and without a lot of wasted search time (reluctant 0N/A * Zero width positive lookahead. 0N/A // Relax transparent region boundaries for lookahead 0N/A // Reinstate region boundaries 0N/A * Zero width negative lookahead. 0N/A // Relax transparent region boundaries for lookahead 0N/A // If a negative lookahead succeeds then more input 0N/A // could cause it to fail! 0N/A // Reinstate region boundaries 0N/A * For use with lookbehinds; matches the position where the lookbehind 0N/A * Zero width positive lookbehind. 0N/A // Relax transparent region boundaries for lookbehind 0N/A * Zero width positive lookbehind, including supplementary 0N/A * characters or unpaired surrogates. 0N/A // Relax transparent region boundaries for lookbehind 0N/A * Zero width negative lookbehind. 0N/A // Relax transparent region boundaries for lookbehind 0N/A // Reinstate region boundaries 0N/A * Zero width negative lookbehind, including supplementary 0N/A * characters or unpaired surrogates. 0N/A // Relax transparent region boundaries for lookbehind 0N/A //Reinstate region boundaries 0N/A * Returns the set union of two CharProperty nodes. 0N/A * Returns the set intersection of two CharProperty nodes. 0N/A * Returns the set difference of two CharProperty nodes. 0N/A * Handles word boundaries. Includes a field to allow this one class to 0N/A * deal with the different types of word boundaries we can match. The word 0N/A * characters include underscores, letters, and digits. Non spacing marks 0N/A * can are also part of a word if they have a base character, otherwise 0N/A * they are ignored for purposes of finding word boundaries. 0N/A // Tried to access char past the end 0N/A // The addition of another char could wreck a boundary 0N/A * Non spacing marks only count as word characters in bounds calculations 0N/A * if they have a base character. 0N/A * Attempts to match a slice in the input using the Boyer-Moore string 0N/A * matching algorithm. The algorithm is based on the idea that the 0N/A * pattern can be shifted farther ahead in the search text if it is 0N/A * matched right to left. 0N/A * The pattern is compared to the input one character at a time, from 0N/A * the rightmost character in the pattern to the left. If the characters 0N/A * all match the pattern has been found. If a character does not match, 0N/A * the pattern is shifted right a distance that is the maximum of two 0N/A * functions, the bad character shift and the good suffix shift. This 0N/A * shift moves the attempted match position through the input more 0N/A * quickly than a naive one position at a time check. 0N/A * The bad character shift is based on the character from the text that 0N/A * did not match. If the character does not appear in the pattern, the 0N/A * pattern can be shifted completely beyond the bad character. If the 0N/A * character does occur in the pattern, the pattern can be shifted to 0N/A * line the pattern up with the next occurrence of that character. 0N/A * The good suffix shift is based on the idea that some subset on the right 0N/A * side of the pattern has matched. When a bad character is found, the 0N/A * pattern can be shifted right by the pattern length if the subset does 0N/A * not occur again in pattern, or by the amount of distance to the 0N/A * next occurrence of the subset in the pattern. 0N/A * Boyer-Moore search methods adapted from code by Amy Yu. 0N/A * Pre calculates arrays needed to generate the bad character 0N/A * shift and the good suffix shift. Only the last seven bits 0N/A * are used to see if chars match; This keeps the tables small 0N/A * and covers the heavily used ASCII range, but occasionally 0N/A * results in an aliased match for the bad character shift. 0N/A // The BM algorithm requires a bit of overhead; 0N/A // If the pattern is short don't use it, since 0N/A // a shift larger than the pattern length cannot 0N/A // Precalculate part of the bad character shift 0N/A // It is a table for where in the pattern each 0N/A // lower 7-bit value occurs 0N/A // Precalculate the good suffix shift 0N/A // i is the shift amount being considered 0N/A // j is the beginning index of suffix being considered 0N/A // Testing for good suffix 0N/A // src[j..len] is a good suffix 0N/A // No match. The array has already been 0N/A // filled up with correct values before. 0N/A // This fills up the remaining of optoSft 0N/A // any suffix can not have larger shift amount 0N/A // then its sub-suffix. Why??? 0N/A // Set the guard value because of unicode compression 0N/A // Loop over all possible match positions in text 0N/A // Loop over pattern from right to left 0N/A // Shift search to the right by the maximum of the 0N/A // bad character shift and the good suffix shift 0N/A // Entire pattern matched starting at i 0N/A // BnM is only used as the leading node in the unanchored case, 0N/A // and it replaced its Start() which always searches to the end 0N/A // if it doesn't find what it's looking for, so hitEnd is true. 0N/A * Supplementary support version of BnM(). Unpaired surrogates are 0N/A * also handled by this class. 0N/A // Loop over all possible match positions in text 0N/A // Loop over pattern from right to left 0N/A // Shift search to the right by the maximum of the 0N/A // bad character shift and the good suffix shift 0N/A // Entire pattern matched starting at i 0N/A/////////////////////////////////////////////////////////////////////////////// 0N/A/////////////////////////////////////////////////////////////////////////////// 0N/A * This must be the very first initializer. 0N/A // Unicode character property aliases, defined in 0N/A // Posix regular expression character classes, defined in