An
engine引擎that
performs执行 match
operations操作on a
character sequence
by
interpreting解释 a
Pattern
.
A matcher匹配器is created from a pattern模式by
invoking调用 the pattern's matcher
method. Once created, a matcher can be used to perform three different kinds of match operations:
-
The matches
method attempts尝试to match the
entire整个的input sequence against the pattern.
-
The lookingAt
method attempts to match the input sequence, starting at the beginning, against the pattern.
-
The find
method scans扫描 the input sequence looking for the next subsequence that matches the pattern.
Each of these methods returns a boolean indicating表示 success or failure. More information about a successful match can be
obtained获得 by querying the state of the matcher.
A matcher finds matches in a subset子集 of its input called the
region区域. By default, the region contains all of the matcher's input. The region can be
modified修改via通过 theregion
method and queried via theregionStart
and
regionEnd
methods. The way that the region boundaries边界 interact with some pattern
constructs构造 can be changed. SeeuseAnchoringBounds
and
useTransparentBounds
for more details.
This class also defines定义 methods for replacing matched subsequences with new strings whose contents can, if
desired需要, be computed计算 (new strings contents)from the match result. TheappendReplacement
and
appendTail
methods can be used in tandem in order to collect the result into an
existing 现有的string buffer, or the more convenientreplaceAll
method can be used to create a string in which every matching subsequence in the input sequence is replaced.
The explicit显示state of a matcher includes the start and end
indices索引of the most recent 最近的successful match. It also includes the start and end indices of the input subsequence
captured捕获 by eachcapturing group in the pattern as well as a total count of such subsequences. As a
convenience方便, methods are also provided for returning these
captured subsequences in string form形式.
The explicit state of a matcher is initially最初undefined;
attempting尝试 to query any part of it before a successful match will cause anIllegalStateException
to be thrown. The explicit state of a matcher is
recomputed重新计算by every match operation.
The implicit 隐式state of a matcher includes the input character sequence as well as theappend position, which is initially zero and is updated by the
appendReplacement
method.
A matcher may be reset explicitly by invoking its reset()
method or, if a new input sequence is
desired需要, itsreset(CharSequence)
method. Resetting a matcher
discards 放弃its explicit state information and sets the append position to zero.
Instances of this class are not safe for use by multiple concurrent并发threads.
相关推荐
Java中的Pattern和Matcher是正则表达式的核心工具类,它们在处理字符串匹配和模式查找时起着关键作用。本文将深入解析这两个类的功能、用法以及相关知识点。 首先,Pattern类是Java.util.regex包下的一个类,它代表...
This is a pattern matcher in common lips. We implement the function match with two parameters: a pattern and a fact. It returns a list of variable-value bindings if the facts match the patterns while ...
### JAVA正则表达式——Pattern和Matcher详解 #### 一、引言 随着JDK 1.4的发布,Java终于内置了自己的正则表达式API,这对于Java开发者来说无疑是个福音,意味着不再需要依赖第三方库就能高效地处理文本数据。Java...
它包括两个类:Pattern和Matcher Pattern 一个Pattern是一个正则表达式经编译后的表现模式。 Matcher 一个Matcher对象是一个状态机器,它依据Pattern对象做为匹配模式对字符串展开匹配检查。 首先一个Pattern实例...
Java正则表达式:Pattern类和Matcher类
java.util.regex是一个用正则表达式所订制的...包括两个类Pattern和Matcher Pattern,Pattern是一个正则表达式经编译后的表现模式。Matcher对象是一个状态机器,它依据Pattern对象做为匹配模式对字符串展开匹配检查。
### Java正则表达式Pattern与Matcher详解 #### 一、Java正则表达式的概述 在Java编程语言中,正则表达式(Regular Expression)是一种强大的文本处理工具,它能够帮助开发者进行复杂的字符串搜索和替换操作。Java...
Matcher是Pattern的一个关键接口,它提供了多种匹配方法来检查字符串是否符合给定的正则表达式。Matcher的主要方法包括: - boolean matches():尝试将整个输入序列与模式匹配。如果输入序列与整个模式完全匹配,则...
正则表达式在Java中通过`Pattern`和`Matcher`类实现,这两个类都位于`java.util.regex`包中。本文将深入探讨这两个类的工作原理,并通过示例代码加深理解。 `Pattern`类是对正则表达式进行编译后得到的模式对象,它...
在Java中,正则表达式相关的操作主要集中在java.util.regex包中,主要包括两个类:Pattern类与Matcher类。Pattern类用于编译正则表达式模式,而Matcher类则用于对输入字符串进行模式匹配。 Matcher类的group方法是...
在Java中,正则表达式的处理主要涉及到两个核心类:`Pattern`和`Matcher`。 `Pattern`类是用于编译正则表达式的,它将文本模式转化为可匹配的模式对象。在给定的例子中,`Pattern.compile("[,\\s]+")`编译了一个...
在Java编程语言中,`Pattern`和`Matcher`是正则表达式处理的核心类,它们位于`java.util.regex`包中。这两个类是Java提供的强大工具,用于处理文本字符串,进行模式匹配、查找、替换等操作。下面我们将深入探讨`...
《PatternMatcher:深入理解Java正则表达式》 在编程世界中,正则表达式(Regular Expression)是一种强大的文本处理工具,它能帮助我们高效地进行字符串匹配、查找、替换等操作。Java作为一门广泛使用的编程语言,...
本文将深入探讨Java正则表达式中的`Pattern`和`Matcher`类,这两个类是处理正则表达式的核心。 首先,`Pattern`类是用于编译正则表达式并创建匹配模式的对象。在Java中,使用`Pattern.compile()`方法编译正则表达式...
开发者应该能够轻松理解和使用提供的方法,如`match(url)`、`extractParams(pattern, url)`等,来实现他们的需求。 **7. 文档与示例** 对于开源项目来说,清晰的文档和丰富的示例是必不可少的。jeefo_url_matcher ...
在Java中,`java.util.regex`包提供了Pattern和Matcher类来支持正则表达式的使用。下面将详细探讨这个主题。 首先,`Pattern`类是正则表达式的编译表示形式,它通过`compile`方法创建,并且可以多次复用。例如,...
dry-matcher, 灵活的,表达式 Pattern 匹配,用于 ruby 干匹配器 灵活的,表达式 Pattern 匹配,用于 ruby 。链接文档文档许可证版权所有 © 2015 -2016 Icelab 。 dry是自由软件,可以根据许可协议中指定的条款重新...
import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.Perl5Matcher; import org.apache.oro.text.regex.Perl5Substitution; ...