memo.xight.org

/ / memo.xight.org

2004-03-15

正規表現 (Pattern, Matcherクラス)

- マッチング
boolean flag = Pattern.matches("正規表現","文字列");


- 置換
Pattern p = Pattern.compile("正規表現");
Matcher m = p.matcher("置換対象文字列");
String result = m.replaceFirst("置換文字列");
String result = m.replaceAll("置換文字列");


- 分割
Pattern p = Pattern.compile("正規表現");
String[] strs = p.split("置換対象文字列");


- 注意
import java.util.regex.*;

  を忘れずに
- Reference
  JavaAPI Documents - Pattern (Java 2 プラットフォーム SE v1.4.0)
  http://java.sun.com/j2se/1.4/ja/docs/ja/api/java/util/regex/Pattern.html
  JavaでHello World 正規表現編
  http://www.hellohiro.com/regex.htm
カテゴリ: [Java][正規表現]
2004-03 /

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-09-05 14:14
Copyright © 2005 xight.org All Rights Reserved.