`
as619864232
  • 浏览: 327452 次
社区版块
存档分类
最新评论

Java Matcher 翻译

阅读更多

 

java.util.regex

Class Matcher

  • All Implemented Interfaces:
    MatchResult


    public final class Matcher
    extends Object
    implements MatchResult
    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 the region method and queried via the regionStart and regionEnd methods. The way that the region boundaries(边界) interact(互相作用) with some pattern constructs(构造) can be changed. See useAnchoringBounds and useTransparentBounds for more details.

    This class also defines methods for replacing matched subsequences with new strings whose contents can, if desired(需求), be computed from the match result. The appendReplacement and appendTail methods can be used in tandem(串联in order to collect(汇集) the result into an existing string buffer, or the more convenient(方便的) replaceAll 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 each capturing 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(导致) an IllegalStateException 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 the append 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(需求), its reset(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语言翻译程序,输入英文翻译到汉语,通过加载自己编写的词汇库进行匹配,能进行一些日常语的翻译.zip

    Java的`Pattern`和`Matcher`类提供了正则表达式的支持。 6. **异常处理**:在处理用户输入和文件读取时,可能会遇到各种异常,比如文件不存在、格式错误等。Java的异常处理机制(try-catch-finally)可以捕获并处理...

    java 判断中英文

    return Pattern.compile("[\u4e00-\u9fa5]").matcher(str).find(); } ``` 而判断英文字符,可以使用: ```java public boolean containsEnglishWithRegex(String str) { return str.matches(".*[a-zA-Z0-9\\s].*...

    JAVA (Jsp)利用Google的Translate开发API

    本文将详细介绍如何使用Java(具体实现方式为JSP)来调用Google Translate API进行文本翻译。作者在文章开头提到已经实现了ASP、PHP 和 C# 版本的Google Translate API 调用方法,并在此基础上提供了一个Java版本的...

    一个java正则表达式工具类源代码.zip(内含Regexp.java文件)

    以前写了一个java的正规表达式的java工具类,分享一下,有用到的欢迎下载使用。 如果你有常用的定义好的,且测试通过的正规表达式,欢迎跟贴,也让我享用一下 . 类中用到了 jakarta-oro-2.0.jar 包,请大家自己在 ...

    外文翻译—Java(译文+英文).doc

    return pattern.matcher(name).matches(); } } } ``` 在这个例子中,我们创建了一个`DirFilter`类,它实现了`FilenameFilter`接口。当传入一个正则表达式时,`accept()`方法会检查每个文件名是否匹配。通过`...

    JAVA (Jsp)利用Google的Translate开发API的代码

    文档提到的代码段并非完整的程序,它缺少了导入java.util.regex.Matcher的语句,此外,在读取输入流时,变量all应该是可用字节(all),而不是未定义的变量。这些错误可能是由于OCR技术在扫描文档时出现的识别错误,...

    表达式解析

    Pattern类提供了编译和执行正则表达式的方法,而Matcher类则用于在输入字符串中查找与模式匹配的子串。这个测试类可能包含了对不同表达式的测试用例,帮助开发者验证解析逻辑的正确性。 接着,"FunctionType.java...

    RegularExpressionTutorial:RegularExpression教程项目通过大量示例解释了核心概念

    开发诸如编译器,解释器和汇编器之类的翻译器。 开发通信协议行TCP / IP,UDP等 正则表达概念 RegularExpression是Java 1.4版本发行的版本,并存在于java.util.regex软件包中。 RegularExpression是一种根据特定...

    regexUserRegisteration

    2. **Java中的Pattern和Matcher类**:在Java中,我们通过`java.util.regex.Pattern`类来编译正则表达式,然后使用`Matcher`类来执行匹配操作。例如,`Pattern.compile("regex")`编译正则,`matcher(input)`创建匹配...

    Android屏幕获取英文单词

    - 可以使用`Pattern`和`Matcher`类进行匹配,如`Pattern.compile("\\b\\w+\\b")`可以匹配英文单词。 4. **处理一行内容**: - 如果示例仅能获取一行内容,可能是因为只考虑了TextView中的行内文本。可以使用`...

    正则表达式之道 Steve

    - **Java**:使用`java.util.regex`包中的`Pattern`和`Matcher`类。 ### 学习资源推荐 对于初学者而言,可以通过以下途径学习和实践正则表达式的使用: - 在线教程:网站如RegExr、RegexOne提供了丰富的学习资源和...

Global site tag (gtag.js) - Google Analytics