易截截图软件、单文件、免安装、纯绿色、仅160KB

Java对正则表达式的支持


1. The java.util.regex API
Now that we've covered the theory of how to construct regular
expressions, the
hard part is over. All that's left is to investigate the Java API for applying
regexes: searching for them in strings, retrieving captured text, and replacing
matches with substitution text.
1.1 Pattern
As we've said, the regex patterns that we write as strings are,
in actuality, little programs describing how to match text. At runtime, the Java
regex package compiles these little programs into a form that it can execute
against some target text. Several simple convenience methods accept strings
directly to use as patterns. More generally, however, Java allows you to
explicitly compile your pattern and encapsulate it in an instance of a
Pattern
object. This is the most efficient way to handle patterns that
are used more than once, because it eliminates needlessly recompiling the
string. To compile a pattern, we use the static method Pattern.compile(
)
:
Pattern urlPattern = Pattern.compile("\\w+://[\\w/]*");
Once you have a Pattern
, you can ask it to create a
Matcher
object, which associates the pattern with a target string:
Matcher matcher = urlPattern.matcher( myText );
The matcher is what actually executes the matches. We'll talk
about it next. But before we do, we'll just mention one convenience method of
Pattern
. The static method Pattern.matches( )
simply takes two
stringsa regex and a target stringand determines if the target matches the
regex. This is very convenient if you want to do a quick test once in your
application. For example:
Boolean match = Pattern.matches( "\\d+\\.\\d+f?", myText );
The previous line of code can test if the string
myText
contains a Java-style floating-point number such as "42.0f."
Note that the string must match completely, to the end, to be considered a
match.
1.2 The Matcher
A Matcher
associates a patt


相关文档:

java使用rocksaw和vserv tcpip实现基于ICMP的Ping功能

一:准备 www.savarese.org download
 1.  rocksaw-1.0.0-src.tar.gz
 2.  vserv-tcpip-0.9.2-src.tar.gz
二:编译源文件得到jar包 使用Ant
 1.  build vserv-tcpip-0.9.2-src
      在vserv-tcpip-0.9.2目录下面建一个tests目录,然后在cmd窗口下进入 ......

Java读取配置文件

import java.util.Properties;
public class ConfigReader {
private static Properties cache = new Properties();
static{
   try {
    cache.load(ConfigReader .class.getClassLoader().getResourceAsStream("config.properties"));
   } catch (Exception e) {
 &nbs ......

java doc


以下文字参考自http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html
 
javadoc工具可以从以下4类“源文件”产生doc:
(1) java源文件(.java),生成对类和类的成员的doc
(2) package注释文件(package-info.java或者package.html),生成对包的说明
(3) overview文件(名可以随便,通常是o ......

java 文件读写_FileInputStream_File

package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
 public static void main(String arg[]) {
  String fileName = "E:\\share\\test.txt";
  File file = new File(fileName);
......

传智播客2009 12 24 二、java基础加强(2)

一、反射(Reflect)
       反射就是把Java类中的各种成分映射成一个个的java对象。例如,一个类有:成员变量,方法,构造方法,包等等信息,利用反射技术可以对一个类进行解剖,把各个组成部分映射成一个个对象。映射成对象后,就可以调用对象的方法对其操作了。与反射相关的重要的类有Cl ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号