Java 正则表达式
原文地址 作者:Jakob Jenkov 译者:严亮
Java 提供了功能强大的正则表达式API,在java.util.regex 包下。本教程介绍如何使用正则表达式API。
正则表达式
一个正则表达式是一个用于文本搜索的文本模式。换句话说,在文本中搜索出现的模式。例如,你可以用正则表达式搜索网页中的邮箱地址或超链接。
正则表达式示例
下面是一个简单的Java正则表达式的例子,用于在文本中搜索 http://
String text = "This is the text to be searched " + "for occurrences of the http:// pattern."; String pattern = ".*http://.*"; boolean matches = Pattern.matches(pattern, text); System.out.println("matches = " + matches);